Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
582e9aa59e | |||
af2ac9af01 | |||
0f46df2318 | |||
7d0dce2d87 | |||
4f4565f5af | |||
048bb1f136 | |||
0d906e3634 | |||
e7148a6963 | |||
d7e238ff13 | |||
cf51bab554 | |||
9b44a5dfc6 | |||
c14ce1a405 | |||
0ad0dc13b9 | |||
54c4f4308e | |||
95f97686f4 | |||
1861b31953 |
48
README.md
48
README.md
@ -4,52 +4,8 @@ Explore our Data Structure Lab repo: codes, lab manuals, write-ups. Ace your ass
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
In this repository, you'll find codes for Data Structure Lab.
|
# ⚠️ THIS IS THE TESTING BRANCH ⚠️
|
||||||
|
|
||||||
## Index
|
**Codes published here may not work as intended.** This branch contains codes which are first tested, reviewed and then merged with the [main branch](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main).
|
||||||
|
|
||||||
### Codes
|
|
||||||
|
|
||||||
1. [DSL - Assignment 1 (Cricket, Badminton, Football)](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/assignment-1.py)
|
|
||||||
2. [DSL - Assignment 2 (Marks)](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/assignment-2.py)
|
|
||||||
5. [DSL - Assignment 5 (String)](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/assignment-5.py)
|
|
||||||
11. DSL - Assignment 11 (Linear, Sentinel, Binary, Fibonnaci Search) - _PENDING_
|
|
||||||
14. [DSL - Assignment 14 (Selection, Bubble Sorting)](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/assignment-14.py)
|
|
||||||
|
|
||||||
### Write-ups
|
|
||||||
|
|
||||||
1. [Assignment 1 - Cricket, Badminton, Football](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/write-ups/assignment%201%20%28cricket%2C%20badminton%2C%20football%29.pdf)
|
|
||||||
2. Assignment 2 - Marks - _PENDING_
|
|
||||||
5. [Assignment 5 - String](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/write-ups/assignment-5%20%28string%29.pdf)
|
|
||||||
11. Assignment 11 - Linear, Sentinel, Binary, Fibonnaci Search - _PENDING_
|
|
||||||
14. [Assignment 14 - Selection, Bubble Sorting](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/write-ups/assignment-11%20%28selection%2C%20bubble%20sort%29.pdf)
|
|
||||||
|
|
||||||
### Lab Manuals
|
|
||||||
|
|
||||||
1. [Assignment 1 - Cricket, Badminton, Football](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/lab-manuals/Lab%20Assignment%20A_01.pdf)
|
|
||||||
2. [Assignment 2 - Marks](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/lab-manuals/Lab%20Assignment%20A_02.pdf)
|
|
||||||
5. [Assignment 5 - String](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/lab-manuals/Lab%20Assignment%20A_05.pdf)
|
|
||||||
11. [Assignment 11 - Linear, Sentinel, Binary, Fibonnaci Search](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/lab-manuals/Lab%20Assignment%20B_11.pdf)
|
|
||||||
14. [Assignment 14 - Selection, Bubble Sorting](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/lab-manuals/Lab%20Assignment%20B_14.pdf)
|
|
||||||
29. [Assignment 29 - Job queue](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/lab-manuals/Lab%20Assignment%20E_29.pdf)
|
|
||||||
31. [Assignment 31 - Double-ended queue](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/lab-manuals/Lab%20Assignment%20E_31.pdf)
|
|
||||||
32. [Assignment 32 - Circular queue](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/lab-manuals/Lab%20Assignment%20E_32.pdf)
|
|
||||||
33. [Mini Project](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/lab-manuals/Miniproject.doc)
|
|
||||||
|
|
||||||
### Notes
|
|
||||||
|
|
||||||
1. [Unit 1 - Introduction to Algorithm and Data Structures](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/notes/Unit%201)
|
|
||||||
2. [Unit 2 - Linear Data Structure Using Sequential Organization](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/notes/Unit%202)
|
|
||||||
3. [Unit 3 - Searching and Sorting](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/notes/Unit%203)
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### Work in progress
|
|
||||||
|
|
||||||
> These are the codes we're working on. They *may not work* the way intended.
|
|
||||||
|
|
||||||
[quicksortEarlyAccess.py](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/quicksortEarlyAccess.py)
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
Maintained by [notkshitij](https://git.kska.io/notkshitij) and [TanmaySpamzzz](https://git.kska.io/TanmaySpamzzz)
|
|
||||||
|
66
all-sorting-algorithms (selection, bubble, quick).py
Normal file
66
all-sorting-algorithms (selection, bubble, quick).py
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
# ALL SORTING ALGORITHMS
|
||||||
|
|
||||||
|
# Selection sort
|
||||||
|
def selectionSort(arr):
|
||||||
|
for i in range(len(arr)):
|
||||||
|
min = i
|
||||||
|
for j in range(i+1, len(arr)):
|
||||||
|
if (arr[j] < arr[min]):
|
||||||
|
min = j
|
||||||
|
temp = arr[i]
|
||||||
|
arr[i] = arr[min]
|
||||||
|
arr[min] = temp
|
||||||
|
print(f"-----\nSorted array (using selection sort) in ascending order is:\t{arr}\n-----\n")
|
||||||
|
|
||||||
|
def bubbleSort(arr):
|
||||||
|
for i in range(len(arr)):
|
||||||
|
for j in range(0, len(arr)-i-1):
|
||||||
|
if (arr[j] > arr[j+1]):
|
||||||
|
temp = arr[j]
|
||||||
|
arr[j] = arr[j+1]
|
||||||
|
arr[j+1] = temp
|
||||||
|
print(f"-----\nSorted array (using bubble sort) in ascending order is:\t{arr}\n-----\n")
|
||||||
|
|
||||||
|
def quickSort(arr):
|
||||||
|
if len(arr) <= 0:
|
||||||
|
return arr
|
||||||
|
|
||||||
|
pivot = arr[len(arr) // 2]
|
||||||
|
|
||||||
|
left = []
|
||||||
|
for i in arr:
|
||||||
|
if (i < pivot):
|
||||||
|
left.append(i)
|
||||||
|
middle = []
|
||||||
|
for i in arr:
|
||||||
|
if (i == pivot):
|
||||||
|
middle.append(i)
|
||||||
|
right = []
|
||||||
|
for i in arr:
|
||||||
|
if (i > pivot):
|
||||||
|
right.append(i)
|
||||||
|
return quickSort(left) + middle + quickSort(right)
|
||||||
|
|
||||||
|
def top5(arr):
|
||||||
|
top_scores = quickSort(arr)
|
||||||
|
print(f"-----\nTop five scores (sorted using quick sort) are:\t{top_scores[-1:-6:-1]}\n-----\n")
|
||||||
|
|
||||||
|
def main():
|
||||||
|
marks = []
|
||||||
|
|
||||||
|
total = int(input("Total number of students are:\t"))
|
||||||
|
for i in range(total):
|
||||||
|
percen = float(input(f"Enter percentage for student {i+1}:\t"))
|
||||||
|
marks.append(percen)
|
||||||
|
|
||||||
|
print(f"\n-----\nPercentages of {total} students are:\t{marks}\n-----")
|
||||||
|
selectionSort(marks)
|
||||||
|
bubbleSort(marks)
|
||||||
|
print(f"\n-----\nSorted array (using quick sort) in ascending order is:\t{quickSort(marks)}\n-----\n")
|
||||||
|
top5(marks)
|
||||||
|
print(marks)
|
||||||
|
|
||||||
|
|
||||||
|
# Calling main function
|
||||||
|
main()
|
||||||
|
|
132
archive/assignment-29_test2kska.cpp
Normal file
132
archive/assignment-29_test2kska.cpp
Normal file
@ -0,0 +1,132 @@
|
|||||||
|
#include <iostream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class queue {
|
||||||
|
// Class for queue.
|
||||||
|
|
||||||
|
int data[30];
|
||||||
|
int front,rear;
|
||||||
|
|
||||||
|
public:
|
||||||
|
queue() {
|
||||||
|
// Constructor that initialises values for front and rear.
|
||||||
|
front=-1;
|
||||||
|
rear=-1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int emptyCheck() {
|
||||||
|
// Check if it's empty
|
||||||
|
if (front==-1) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int fullCheck() {
|
||||||
|
// Check if it's full
|
||||||
|
if (rear>=30) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void enqueue(int x) {
|
||||||
|
// Add job to queue
|
||||||
|
if (fullCheck()==1) {
|
||||||
|
cout<<endl<<"Job queue is full."<<endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
else {
|
||||||
|
if (front==-1) {
|
||||||
|
front++;
|
||||||
|
}
|
||||||
|
rear++;
|
||||||
|
data[rear]=x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dequeue() {
|
||||||
|
// Remove job from queue.
|
||||||
|
int x;
|
||||||
|
if (emptyCheck()) {
|
||||||
|
cout<<endl<<"Job queue is empty."<<endl;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
x=data[front];
|
||||||
|
front++;
|
||||||
|
cout<<endl<<"Job ["<<x<<"] has been deleted.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void display() {
|
||||||
|
// Displaying job queue.
|
||||||
|
cout<<"Job queue is:\t[ ";
|
||||||
|
for (int i=front; i<=rear; i++) {
|
||||||
|
cout<<data[i]<<" | ";
|
||||||
|
}
|
||||||
|
cout<<"]"<<endl;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
// Main function
|
||||||
|
int choice, job, totalJobs;
|
||||||
|
queue jobQueue;
|
||||||
|
|
||||||
|
//Input inital jobs
|
||||||
|
cout<<"Enter number of jobs:\t";
|
||||||
|
cin>>totalJobs;
|
||||||
|
for (int i=0; i<totalJobs; i++) {
|
||||||
|
cout<<endl<<"Enter job number "<<i+1<<":\t";
|
||||||
|
cin>>job;
|
||||||
|
jobQueue.enqueue(job);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
cout<<endl<<"----- JOB QUEUE MENU -----"<<endl;
|
||||||
|
cout<<endl<<"1 -> Add job to queue"<<endl;
|
||||||
|
cout<<endl<<"2 -> Delete a job from queue"<<endl;
|
||||||
|
cout<<endl<<"3 -> Display queue"<<endl;
|
||||||
|
cout<<endl<<"4 -> Exit"<<endl;
|
||||||
|
cout<<endl<<endl<<"Choose an option (1-4):\t";
|
||||||
|
cin>>choice;
|
||||||
|
|
||||||
|
switch (choice) {
|
||||||
|
case 1:
|
||||||
|
cout<<"Add additional job:\t";
|
||||||
|
cin>>job;
|
||||||
|
jobQueue.enqueue(job);
|
||||||
|
cout<<"\n==============\n";
|
||||||
|
jobQueue.display();
|
||||||
|
cout<<"=============\n";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
jobQueue.dequeue();
|
||||||
|
cout<<"\n==============\n";
|
||||||
|
jobQueue.display();
|
||||||
|
cout<<"=============\n";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
cout<<"\n==============\n";
|
||||||
|
jobQueue.display();
|
||||||
|
cout<<"=============\n";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
cout<<"\n## DESIGNED AND ENGINEERED BY KSHITIJ\n## END OF CODE\n\n";
|
||||||
|
exit(0);
|
||||||
|
|
||||||
|
default:
|
||||||
|
cout<<endl<<"Please choose a valid option (1-4)."<<endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
}
|
103
archive/assignment-29_test3kska.cpp
Normal file
103
archive/assignment-29_test3kska.cpp
Normal file
@ -0,0 +1,103 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
const int MAX_QUEUE_SIZE = 100;
|
||||||
|
|
||||||
|
class JobQueue {
|
||||||
|
private:
|
||||||
|
int queue[MAX_QUEUE_SIZE];
|
||||||
|
int front, rear;
|
||||||
|
|
||||||
|
public:
|
||||||
|
JobQueue() {
|
||||||
|
front = -1;
|
||||||
|
rear = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isFull() {
|
||||||
|
return rear == MAX_QUEUE_SIZE - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isEmpty() {
|
||||||
|
return front == -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void enqueue(int job) {
|
||||||
|
if (isFull()) {
|
||||||
|
std::cout << "Queue is full. Job cannot be added.\n";
|
||||||
|
} else {
|
||||||
|
if (isEmpty()) {
|
||||||
|
front = 0;
|
||||||
|
}
|
||||||
|
rear++;
|
||||||
|
queue[rear] = job;
|
||||||
|
std::cout << "Job " << job << " added to the queue.\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dequeue() {
|
||||||
|
if (isEmpty()) {
|
||||||
|
std::cout << "Queue is empty. No job to delete.\n";
|
||||||
|
} else {
|
||||||
|
int job = queue[front];
|
||||||
|
if (front == rear) {
|
||||||
|
front = rear = -1;
|
||||||
|
} else {
|
||||||
|
front++;
|
||||||
|
}
|
||||||
|
std::cout << "Job " << job << " deleted from the queue.\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void display() {
|
||||||
|
if (isEmpty()) {
|
||||||
|
std::cout << "Queue is empty.\n";
|
||||||
|
} else {
|
||||||
|
std::cout << "Job Queue: ";
|
||||||
|
for (int i = front; i <= rear; i++) {
|
||||||
|
std::cout << queue[i] << " ";
|
||||||
|
}
|
||||||
|
std::cout << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
JobQueue jobQueue;
|
||||||
|
int choice, job;
|
||||||
|
|
||||||
|
while (1) {
|
||||||
|
std::cout << "Job Queue Simulation Menu:\n";
|
||||||
|
std::cout << "1. Add a job to the queue\n";
|
||||||
|
std::cout << "2. Delete a job from the queue\n";
|
||||||
|
std::cout << "3. Display the queue\n";
|
||||||
|
std::cout << "4. Quit\n";
|
||||||
|
std::cout << "Enter your choice: ";
|
||||||
|
std::cin >> choice;
|
||||||
|
|
||||||
|
switch (choice) {
|
||||||
|
case 1:
|
||||||
|
std::cout << "Enter the job number: ";
|
||||||
|
std::cin >> job;
|
||||||
|
jobQueue.enqueue(job);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
jobQueue.dequeue();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
jobQueue.display();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
exit(0);
|
||||||
|
|
||||||
|
default:
|
||||||
|
std::cout << "Invalid choice. Please try again.\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
31
archive/quicksortEarlyAccess.py
Normal file
31
archive/quicksortEarlyAccess.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# Function for quick sort:
|
||||||
|
def quicksort(arr):
|
||||||
|
if len(arr) <= 1:
|
||||||
|
return arr
|
||||||
|
|
||||||
|
pivot = arr[len(arr) // 2]
|
||||||
|
left = [x for x in arr if x < pivot]
|
||||||
|
middle = [x for x in arr if x == pivot]
|
||||||
|
right = [x for x in arr if x > pivot]
|
||||||
|
|
||||||
|
return quicksort(left) + middle + quicksort(right)
|
||||||
|
|
||||||
|
# Function for displaying top scores:
|
||||||
|
def top5(arr):
|
||||||
|
sorted_arr = quicksort(arr)
|
||||||
|
top_scores = sorted_arr[-5:][::-1]
|
||||||
|
return top_scores
|
||||||
|
|
||||||
|
# Defining main function:
|
||||||
|
def main():
|
||||||
|
total=int(input("Total number of students are:\t"))
|
||||||
|
percent=[]
|
||||||
|
for i in range(total):
|
||||||
|
percent_in=float(input(f"Enter percentage for student {i+1}:\t"))
|
||||||
|
percent.append(percent_in)
|
||||||
|
print(f"\nPercentages of students are:\t {percent}")
|
||||||
|
print(f"\n------------------\nSorted marks (using quick sort algorithm):\t{quicksort(percent)}\n------------------")
|
||||||
|
print(f"\n------------------\nTop five scores are:\t{top5(percent)}\n------------------\n")
|
||||||
|
|
||||||
|
# Calling main function:
|
||||||
|
main()
|
117
assignment-1.py
117
assignment-1.py
@ -1,117 +0,0 @@
|
|||||||
# DSL Assignment - 1
|
|
||||||
|
|
||||||
# List of players
|
|
||||||
|
|
||||||
cricket_players=[]
|
|
||||||
badminton_players=[]
|
|
||||||
football_players=[]
|
|
||||||
|
|
||||||
# Input values
|
|
||||||
|
|
||||||
## List for cricket players
|
|
||||||
def cricket_in():
|
|
||||||
total=int(input("Total number of students playing cricket: \t"))
|
|
||||||
for i in range(total):
|
|
||||||
players=int(input("Enter roll number: \t"))
|
|
||||||
cricket_players.append(players)
|
|
||||||
print("Roll numbers of", total, "students playing cricket: \t", cricket_players)
|
|
||||||
cricket_in()
|
|
||||||
|
|
||||||
## List for badminton players
|
|
||||||
def badminton_in():
|
|
||||||
total=int(input("Total number of students playing badminton: \t"))
|
|
||||||
for i in range(total):
|
|
||||||
players=int(input("Enter roll number: \t"))
|
|
||||||
badminton_players.append(players)
|
|
||||||
print("Roll numbers of", total, "students playing badminton: \t", badminton_players)
|
|
||||||
badminton_in()
|
|
||||||
|
|
||||||
## List for football players
|
|
||||||
def football_in():
|
|
||||||
total=int(input("Total number of students playing football: \t"))
|
|
||||||
for i in range(total):
|
|
||||||
players=int(input("Enter roll number: \t"))
|
|
||||||
football_players.append(players)
|
|
||||||
print("Roll numbers of", total, "students playing football: \t", football_players)
|
|
||||||
football_in()
|
|
||||||
|
|
||||||
# List of students playing cricket+badminton
|
|
||||||
|
|
||||||
cricket_and_badminton=[]
|
|
||||||
|
|
||||||
def cricket_and_badminton_fn():
|
|
||||||
for i in cricket_players:
|
|
||||||
if i in badminton_players:
|
|
||||||
cricket_and_badminton.append(i)
|
|
||||||
print("Roll numbers of students playing cricket and badminton are: \t", cricket_and_badminton)
|
|
||||||
|
|
||||||
# List of students playing either cricket or badminton but not both
|
|
||||||
|
|
||||||
cricket_or_badminton=[]
|
|
||||||
|
|
||||||
def cricket_or_badminton_fn():
|
|
||||||
for i in cricket_players:
|
|
||||||
if i not in badminton_players:
|
|
||||||
cricket_or_badminton.append(i)
|
|
||||||
for i in badminton_players:
|
|
||||||
if i not in cricket_players:
|
|
||||||
cricket_or_badminton.append(i)
|
|
||||||
print("Roll numbers of students playing either cricket or badminton are: \t", cricket_or_badminton)
|
|
||||||
|
|
||||||
# Number of students playing neither cricket nor badminton
|
|
||||||
|
|
||||||
football_only=[]
|
|
||||||
football_only_1=[]
|
|
||||||
|
|
||||||
def football_only_fn():
|
|
||||||
for i in cricket_players:
|
|
||||||
football_only.append(i)
|
|
||||||
for i in badminton_players:
|
|
||||||
if i not in cricket_players:
|
|
||||||
football_only.append(i)
|
|
||||||
for i in football_players:
|
|
||||||
if i not in football_only:
|
|
||||||
football_only_1.append(i)
|
|
||||||
print("Number of students playing neither cricket nor badminton: \t", len(football_only_1), "\n Roll numbers are:\t", football_only_1)
|
|
||||||
|
|
||||||
# Number of students playing cricket and football but not badminton
|
|
||||||
|
|
||||||
not_badminton=[]
|
|
||||||
|
|
||||||
def not_badminton_fn():
|
|
||||||
for i in badminton_players:
|
|
||||||
if i not in cricket_players:
|
|
||||||
not_badminton.append(i)
|
|
||||||
for i in badminton_players:
|
|
||||||
if i not in football_players:
|
|
||||||
not_badminton.append(i)
|
|
||||||
print("Number of students playing cricket and football but not badminton: \t", len(not_badminton), "\n Roll numbers are:\t", not_badminton)
|
|
||||||
|
|
||||||
# Choosing an option
|
|
||||||
def choose_optn():
|
|
||||||
while True:
|
|
||||||
print("Choose an operation to perform:")
|
|
||||||
print("1. List of students playing cricket and badminton both")
|
|
||||||
print("2. List of students playing either cricket or badminton")
|
|
||||||
print("3. List of students playing neither cricket nor badminton")
|
|
||||||
print("4. List of students playing cricket and football but not badminton")
|
|
||||||
print("5. Exit")
|
|
||||||
optn=int(input("Enter option number (1-5): \t"))
|
|
||||||
if optn==1:
|
|
||||||
cricket_and_badminton_fn()
|
|
||||||
if optn==2:
|
|
||||||
cricket_or_badminton_fn()
|
|
||||||
if optn==3:
|
|
||||||
football_only_fn()
|
|
||||||
if optn==4:
|
|
||||||
not_badminton_fn()
|
|
||||||
if optn==5:
|
|
||||||
print("## DESIGNED AND ENGINEERED BY KSHITIJ\n## END OF CODE")
|
|
||||||
quit()
|
|
||||||
else:
|
|
||||||
print("\nPlease choose a valid option.\n")
|
|
||||||
choose_optn()
|
|
||||||
choose_optn()
|
|
||||||
|
|
||||||
## END OF CODE
|
|
||||||
|
|
@ -1,62 +0,0 @@
|
|||||||
# Sorting (Selection+Bubble) and Top 5
|
|
||||||
|
|
||||||
marks=[]
|
|
||||||
|
|
||||||
# Function to enter marks of students
|
|
||||||
def input_marks():
|
|
||||||
students=int(input("Enter the number of students:\t"))
|
|
||||||
for i in range(students):
|
|
||||||
marks_in=float(input("Enter the marks (out of 50):\t"))
|
|
||||||
marks.append(marks_in)
|
|
||||||
print("\nThe marks you've entered for ", students, "students are: ", marks, "\n")
|
|
||||||
|
|
||||||
# Function for selection sort
|
|
||||||
def selection():
|
|
||||||
for i in range(len(marks)):
|
|
||||||
min_index=i
|
|
||||||
for j in range(i+1, len(marks)):
|
|
||||||
if marks[j] < marks[min_index]:
|
|
||||||
min_index=j
|
|
||||||
marks[i], marks[min_index] = marks[min_index], marks[i]
|
|
||||||
print("Marks sorted in ascending order using selection sort:\t", marks)
|
|
||||||
|
|
||||||
def bubble():
|
|
||||||
for i in range(len(marks)):
|
|
||||||
for j in range(0, len(marks)-i-1):
|
|
||||||
if marks[j]>marks[j+1]:
|
|
||||||
marks[j], marks[j+1] = marks[j+1], marks[j]
|
|
||||||
print("Marks sorted in ascending order using bubble sort:\t", marks)
|
|
||||||
|
|
||||||
def top5():
|
|
||||||
for i in range(len(marks)):
|
|
||||||
for j in range(0, len(marks)-i-1):
|
|
||||||
if marks[j]>marks[j+1]:
|
|
||||||
marks[j], marks[j+1] = marks[j+1], marks[j]
|
|
||||||
print("Top 5 marks using bubble sorting:\t", marks[::-1])
|
|
||||||
|
|
||||||
|
|
||||||
def choose_optn():
|
|
||||||
while True:
|
|
||||||
print("Choose an option from the menu below:")
|
|
||||||
print("1 -> Input marks")
|
|
||||||
print("2 -> Selection Sorting")
|
|
||||||
print("3 -> Bubble Sorting")
|
|
||||||
print("4 -> Display top 5")
|
|
||||||
print("5 -> Exit")
|
|
||||||
optn=int(input("Choose an option (1-5):\t"))
|
|
||||||
|
|
||||||
if optn==1:
|
|
||||||
input_marks()
|
|
||||||
elif optn==2:
|
|
||||||
selection()
|
|
||||||
elif optn==3:
|
|
||||||
bubble()
|
|
||||||
elif optn==4:
|
|
||||||
top5()
|
|
||||||
elif optn==5:
|
|
||||||
print("## DESIGNED AND ENGINEERED BY KSHITIJ\n## END OF CODE")
|
|
||||||
quit()
|
|
||||||
else:
|
|
||||||
print("\nPlease choose a valid option (1-5).\n")
|
|
||||||
choose_optn()
|
|
||||||
choose_optn()
|
|
@ -1,92 +0,0 @@
|
|||||||
# DSL - Assignment 2
|
|
||||||
|
|
||||||
students=[]
|
|
||||||
marks=[]
|
|
||||||
total_students_in=int(input("Total number of students are: \t"))
|
|
||||||
|
|
||||||
# Entering marks
|
|
||||||
def total_students_fn():
|
|
||||||
for i in range(total_students_in):
|
|
||||||
marks_in=int(input("Enter marks for DSA subject for each student (out of 50) (enter -1 for absent students): \t"))
|
|
||||||
marks.append(marks_in)
|
|
||||||
print("Marks of", total_students_in, "students in DSA subject are:", marks)
|
|
||||||
|
|
||||||
total_students_fn()
|
|
||||||
|
|
||||||
# Option 1 = Average
|
|
||||||
def average_marks():
|
|
||||||
for i in marks:
|
|
||||||
if i<0:
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
average_calc=sum(marks)/total_students_in
|
|
||||||
print("Average score of", total_students_in, "is: \t", average_calc)
|
|
||||||
|
|
||||||
# Option 2 = Highest and lowest
|
|
||||||
def high_low():
|
|
||||||
mini=marks[0]
|
|
||||||
maxi=marks[0]
|
|
||||||
for i in range (len(marks)):
|
|
||||||
if (maxi<marks[i] and marks[i]>-1):
|
|
||||||
maxi=marks[i]
|
|
||||||
for j in range (len(marks)):
|
|
||||||
if (mini>marks[j] and marks[j]>-1):
|
|
||||||
mini=marks[j]
|
|
||||||
print("Highest marks are: \t", maxi)
|
|
||||||
print("Lowest marks are: \t", mini)
|
|
||||||
|
|
||||||
# Option 3 = Absent
|
|
||||||
def absent():
|
|
||||||
absent_count=0
|
|
||||||
for i in marks:
|
|
||||||
if i==-1:
|
|
||||||
absent_count+=1
|
|
||||||
print("Total number of absent students out of", total_students_in, "are: \t", absent_count)
|
|
||||||
|
|
||||||
# Option 4 = Highest freq
|
|
||||||
def high_freq():
|
|
||||||
freq_count=0
|
|
||||||
for i in range(len(marks)):
|
|
||||||
if (i>=0):
|
|
||||||
count=0
|
|
||||||
for j in range(len(marks)):
|
|
||||||
if (marks[i]==marks[j]):
|
|
||||||
count+=1
|
|
||||||
if (freq_count<count):
|
|
||||||
freq_count=count
|
|
||||||
else:
|
|
||||||
break
|
|
||||||
print("Highest frequency is: \t", freq_count)
|
|
||||||
|
|
||||||
# Choosing an option
|
|
||||||
def choose_optn():
|
|
||||||
while True:
|
|
||||||
print("Choose an operation to perform:")
|
|
||||||
print("1. Average score of all students")
|
|
||||||
print("2. Highest and lowest score out of all students")
|
|
||||||
print("3. Count of students absent for test")
|
|
||||||
print("4. Display marks with highest frequency")
|
|
||||||
print("5. Exit")
|
|
||||||
optn=int(input("Enter option number (1-5): \t"))
|
|
||||||
if optn==1:
|
|
||||||
average_marks()
|
|
||||||
print("Designed and Engineered by Kshitij")
|
|
||||||
elif optn==2:
|
|
||||||
high_low()
|
|
||||||
print("Designed and Engineered by Kshitij")
|
|
||||||
elif optn==3:
|
|
||||||
absent()
|
|
||||||
print("Designed and Engineered by Kshitij")
|
|
||||||
elif optn==4:
|
|
||||||
high_freq()
|
|
||||||
print("Designed and Engineered by Kshitij")
|
|
||||||
elif optn==5:
|
|
||||||
print("## Designed and Engineered by Kshitij\n## END OF CODE.")
|
|
||||||
quit()
|
|
||||||
else:
|
|
||||||
print("\n Invalid option selected. Please choose from range 1 to 5. \n")
|
|
||||||
choose_optn()
|
|
||||||
|
|
||||||
choose_optn()
|
|
||||||
|
|
||||||
## END OF CODE
|
|
@ -1,99 +0,0 @@
|
|||||||
str1 = input("Enter string: ")
|
|
||||||
substr1 = input("Enter substring: ")
|
|
||||||
occur1 = input("Enter character whose occurence is to be calculated: ")
|
|
||||||
occur2 = str1.split()
|
|
||||||
index1 = []
|
|
||||||
for i in occur2:
|
|
||||||
for j in occur2:
|
|
||||||
if(i == j and j not in index1):
|
|
||||||
index1.append(i)
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
|
|
||||||
def longestWord():
|
|
||||||
globalMax = 0
|
|
||||||
currentMax = 0
|
|
||||||
list1 = []
|
|
||||||
for i in str1:
|
|
||||||
if (i != " "):
|
|
||||||
currentMax = currentMax + 1
|
|
||||||
list1.append(i)
|
|
||||||
else:
|
|
||||||
if (currentMax > globalMax):
|
|
||||||
globalMax = currentMax
|
|
||||||
temp = list1
|
|
||||||
currentMax = 0
|
|
||||||
list1 = []
|
|
||||||
if (i == str1[len(str1) - 1]):
|
|
||||||
if (currentMax > globalMax):
|
|
||||||
globalMax = currentMax
|
|
||||||
temp = list1
|
|
||||||
print("Longest word is: ", "".join(temp))
|
|
||||||
print("Length of largest word is: ", globalMax)
|
|
||||||
|
|
||||||
|
|
||||||
def palindrome():
|
|
||||||
rev1 = str1
|
|
||||||
if (str1[::-1] == rev1):
|
|
||||||
print("String is palindrome")
|
|
||||||
else:
|
|
||||||
print("String is not palindrome")
|
|
||||||
|
|
||||||
|
|
||||||
def charfrequency():
|
|
||||||
temp = 0
|
|
||||||
for i in str1:
|
|
||||||
max1 = 0
|
|
||||||
for j in range(0, len(str1)):
|
|
||||||
if (str1[j] != " " and str1[j] == occur1):
|
|
||||||
max1 = max1 + 1
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
if (max1 > temp):
|
|
||||||
temp = max1
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
print("Number of times the character '", occur1, "' occurs: ", temp)
|
|
||||||
|
|
||||||
|
|
||||||
def indexSubstring():
|
|
||||||
for i in range(len(str1) - len(substr1) + 1):
|
|
||||||
if str1[i:i + len(substr1)] == substr1:
|
|
||||||
print("Substring present in string at index: ", i)
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
print('Substring not present')
|
|
||||||
|
|
||||||
def occurWord():
|
|
||||||
for i in index1:
|
|
||||||
max1 = 0
|
|
||||||
for j in occur2:
|
|
||||||
if(i == j):
|
|
||||||
max1 = max1 + 1
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
print("The number of times '",i,"' is repeated is: ",max1)
|
|
||||||
|
|
||||||
flag = 1
|
|
||||||
while flag == 1:
|
|
||||||
print("1. Display word with longest word: \n")
|
|
||||||
print("2. The occurence of '",occur1,"' in the string is: \n")
|
|
||||||
print("3. Check whether is string is palindrome or not: \n")
|
|
||||||
print("4. Display index of first appearance of the substring: \n")
|
|
||||||
print("5. Occurrence of each word in the given string: \n")
|
|
||||||
print("6. Exit")
|
|
||||||
ch = int(input("Enter your choice: "))
|
|
||||||
if(ch == 1):
|
|
||||||
longestWord()
|
|
||||||
elif(ch == 2):
|
|
||||||
charfrequency()
|
|
||||||
elif(ch == 3):
|
|
||||||
palindrome()
|
|
||||||
elif(ch == 4):
|
|
||||||
indexSubstring()
|
|
||||||
elif(ch == 5):
|
|
||||||
occurWord()
|
|
||||||
elif(ch>6 or ch<1):
|
|
||||||
print("Enter valid choice")
|
|
||||||
elif(ch == 6):
|
|
||||||
flag = 0
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,38 +0,0 @@
|
|||||||
no = int(input("Enter number of students: "))
|
|
||||||
list2 = []
|
|
||||||
#list1 = []
|
|
||||||
for i in range(0,no):
|
|
||||||
n = float(input("Enter % of student: "))
|
|
||||||
list2.append(n)
|
|
||||||
print(list2)
|
|
||||||
|
|
||||||
d = len(list2)
|
|
||||||
|
|
||||||
def partition(list3,a,b):
|
|
||||||
v = list3[a]
|
|
||||||
i = a
|
|
||||||
j = b-1
|
|
||||||
temp = 0
|
|
||||||
while(i<j):
|
|
||||||
while(list3[i]<=v and i<=j):
|
|
||||||
i = i + 1
|
|
||||||
while(list3[j] > v):
|
|
||||||
j = j - 1
|
|
||||||
if(i<j):
|
|
||||||
temp = list3[i]
|
|
||||||
list3[i] = list3[j]
|
|
||||||
list3[j] = temp
|
|
||||||
list3[a] = list3[j]
|
|
||||||
list3[j] = v
|
|
||||||
return j
|
|
||||||
|
|
||||||
def quicksort(list1, l, u):
|
|
||||||
j = 0
|
|
||||||
if(l<u):
|
|
||||||
j = partition(list1,l,u)
|
|
||||||
quicksort(list1,l,j - 1)
|
|
||||||
quicksort(list1,j+1,u)
|
|
||||||
list2 = list1
|
|
||||||
return list2
|
|
||||||
o = quicksort(list2,0,d)
|
|
||||||
print("Sorted list is: ",o)
|
|
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue
Block a user