Compare commits

..

16 Commits

Author SHA1 Message Date
582e9aa59e
just having fun at this point with sorting algos. this file contains all sorting algos in our syllabus (selection sort, quick sort, bubble sort) and top 5 function 2023-12-10 19:59:22 +05:30
af2ac9af01
merged assignment 31 and 32 codes in main branch 2023-10-28 16:52:24 +05:30
0f46df2318
Added codes for assignment 31 and 32 given by ma'am 2023-10-19 23:13:51 +05:30
7d0dce2d87
moved assignment-29_test2kska.cpp to archive since it has been merged with the main branch 2023-10-16 20:23:09 +05:30
4f4565f5af
moved assignment-29_test2kska.cpp to archive since it has been merged with the main branch 2023-10-16 20:22:02 +05:30
048bb1f136
Completely working queue code (assignment-29) 2023-10-16 20:18:55 +05:30
0d906e3634
moved assignment-29 given by ma'am to archive 2023-10-16 20:18:11 +05:30
e7148a6963
Quick sort code completely made by chatgpt **only for reference** 2023-10-16 20:16:11 +05:30
d7e238ff13
Restored quick access file and moved it to archive 2023-10-16 20:15:36 +05:30
cf51bab554
Merged quick sort in main branch 2023-10-16 19:36:00 +05:30
9b44a5dfc6
Fixed quick sort and added top 5 2023-10-16 19:30:05 +05:30
c14ce1a405
Fixed quick sort 2023-10-16 19:07:36 +05:30
0ad0dc13b9
Moved quick sort algorithm from main branch to testing branch 2023-09-29 16:55:00 +05:30
54c4f4308e
Moved assignment-29 file from main branch to testing branch 2023-09-29 16:55:00 +05:30
95f97686f4
Added README file 2023-09-29 16:54:47 +05:30
1861b31953
New branch, testing 2023-09-29 15:48:26 +05:30
70 changed files with 394 additions and 39952 deletions

2
.gitignore vendored
View File

@ -194,5 +194,3 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
# VIM swap file
*.swp

Binary file not shown.

Binary file not shown.

View File

@ -1,97 +1,11 @@
# DSL
Explore our Data Structure Lab repository: codes, lab manuals, write-ups. Ace your assignments with practical examples and clear guidance.
Explore our Data Structure Lab repo: codes, lab manuals, write-ups. Ace your assignments with practical examples and clear guidance.
---
In this repository, you'll find codes for Data Structure Lab.
# ⚠️ THIS IS THE TESTING BRANCH ⚠️
## Index
### 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)](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/assignment-11.py)
14. [DSL - Assignment 14 (Selection, Bubble Sorting)](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/assignment-14.py)
16. [DSL - Assignment 16 (Quick sort)](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/assignment-16.py)
19. [DSL - Assignment 19 (Pinnacle Club)](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/assignment-19.cpp)
20. [DSL - Assignment 20 (Cinemax theater)](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/assignment-20.cpp)
26. [DSL - Assignment 26 (Stack Expression)](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/assignment-26.cpp)
27. [DSL - Assignment 27 (Infix to Postfix)](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/assignment-27.cpp)
29. [DSL - Assignment 29 (Queue job)](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/assignment-29.cpp)
31. [DSL - Assignment 31 (Double-ended queue)](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/assignment-31.cpp)
32. [DSL - Assignment 32 (Circular queue)](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/assignment-32.cpp)
### 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](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/write-ups/assignment-2%20%28marks%29.pdf)
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, Fibonacci Search](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/write-ups/assignment-11%20%28Linear%2C%20Sentinel%2C%20Binary%2C%20Fibonacci%20Search%29.pdf)
14. [Assignment 14 - Selection, Bubble Sorting](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/write-ups/assignment-14%20%28selection%2C%20bubble%20sort%29.pdf)
16. [Assignment 16 - Quick sort](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/write-ups/assignment-16%20%28quick%20sort%29.pdf)
19. [Assignment 19 - Pinnacle Club](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/write-ups/assignment-19%20%28singly%20linked%20list%29.pdf)
20. [Assignment 20 - Cinemax Theatre](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/write-ups/assignment-20%20%28Cinemax%20Theatre%29.pdf)
26. [Assignment 26 - Stack Expression](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/write-ups/assignment-26%20%28stack%20expression%29.pdf)
27. [Assignment 27 - Infix to Prefix](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/write-ups/assignment-27%20%28Infix%20to%20Prefix%29.pdf)
29. [Assignment 29 - Queue job](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/write-ups/assignment-29%20%28queue%29.pdf)
31. [Assignment 31 - Double-ended queue](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/write-ups/assignment-31%20%28double-ended%20queue%29.pdf)
32. [Assignment 32 - Circular queue](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/write-ups/assignment-32%20%28circular%20queue%29.pdf)
### Lab Manuals
- [DSL Index](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/DSL%20Index.pdf)
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)
16. [Assignment 16 - Quick sort](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/lab-manuals/Lab%20Assignment%20B_16.pdf)
19. [Assignment 19 - Pinnacle Club](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/lab-manuals/Lab%20Assignment%20C_19.pdf)
20. [Assignment 20 - Cinemax theater](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/lab-manuals/Lab%20Assignment%20C_20.pdf)
26. [Assignment 26 - Stack (Expression)](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/lab-manuals/Lab%20Assignment%20D_26.pdf)
27. [Assignment 27 - Stack (Infix to posfix)](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/lab-manuals/Lab%20Assignment%20D_27.pdf)
29. [Assignment 29 - Queue job](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
- [Endsem Important Notes (Unit 3->6)](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/FDS%20Endsem%20Important%20Notes.pdf) (handwritten by [shh_itsourlittlesecret (Afan)](https://git.kska.io/shh_itsourlittlesecret))
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)
- [Quick Sort](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/notes/Unit%203/quicksort.ppt)
4. [Unit 4 - Linked List](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/notes/Unit%204)
5. [Unit 5 - Stack](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/notes/Unit%205)
6. [Unit 6 - Queue](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/notes/Unit%206/UNIT%20VI%20Queue.pptx)
- [Dequeue](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/notes/Unit%206/Dqueue.cpp)
- [Priority Queue](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/notes/Unit%206/priorityQueue.cpp)
### [Question Bank](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/notes/Deore%27s%20QBank.docx)
### Question Papers
1. [IN-SEM](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/question-papers/IN-SEM)
2. [END-SEM](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/question-papers/END-SEM)
### Diwali work
1. [Assignment 1 - Questions](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/diwali-work/Assignment1_FDS.pdf)
- [Assignment 1 - Solutions](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/diwali-work/Assignment-1%20%28diwali%29.pdf)
2. [Assignment 2 - Questions](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/diwali-work/Assignment2_FDS.pdf)
- [Assignment 2 - Solutions](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/diwali-work/Assignment-2%20%28diwali%29.pdf)
---
### Work in progress
> These are the codes we're working on. They *may not work* the way intended.
> To view all the codes that are being built, checkout the [testing branch](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/testing).
**ALL TESTING CODES MERGED IN MAIN BRANCH. NO CHANGES PENDING.**
**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).
---
Maintained by:
- [notkshitij](https://git.kska.io/notkshitij)
- [TanmaySpamzzz](https://git.kska.io/TanmaySpamzzz)
- [shh_itsourlittlesecret (Afan)](https://git.kska.io/shh_itsourlittlesecret)
Contributor: [Kalaskar_admin03](https://git.kska.io/Kalaskar_admin03/)

View 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()

View File

@ -0,0 +1,190 @@
#include <iostream>
using namespace std;
class queue
{
int data[20];
int f, r;
public:
queue()
{
f = -1;
r = -1;
}
int isempty()
{
if (f == -1)
{
return 1;
}
else
{
return 0;
}
}
int isfull()
{
if (r >= 20)
{
return 1;
}
else
{
return 0;
}
}
void enqueue(int x)
{
if (isfull() == 1)
{
cout << "job queue is full" << endl;
}
else
{
if (f == -1)
f++;
r++;
data[r] = x;
}
}
void dequeue()
{
int x;
if (isempty())
{
cout << "job queue is empty" << endl;
}
else
{
x = data[f];
f++;
cout << x << "Job deleted " << endl;
}
}
void disp()
{
cout << "job queue is as :" << endl;
for (int i = f; i <= r; i++)
{
cout << data[i] << " ";
}
cout << endl;
}
};
int main()
{
int ch, n, x, d;
queue q;
cout << "Enter the no. of jobs in queue. " << endl;
cin >> n;
cout << "Enter jobs " << endl;
for (int i = 0; i < n; i++)
{
cin >> d;
q.enqueue(d);
}
do
{
cout << "**********MENU**********" << endl;
cout << "1)Add job " << endl;
cout << "2)Delete job " << endl;
cout << "3)Display" << endl;
cout << endl;
cout << "Enter your choice " << endl;
cin >> ch;
switch (ch)
{
case 1:
cout << "Enter the job to be added " << endl;
cin >> d;
q.enqueue(d);
cout << "Job added" << endl;
q.disp();
break;
case 2:
q.dequeue();
q.disp();
break;
case 3:
q.disp();
break;
default:
cout << "Invalid choice" << endl;
break;
}
cout << "Do you want to continue" << endl;
cout << "1. YES" << endl;
cout << "2. NO" << endl;
cin >> x;
} while (x == 1);
}
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~ Output ~~~~~~~~~~~~~~~~~~~~~~~~~
Enter the no. of jobs in queue.
10
Enter jobs
1
2
3
4
5
6
7
8
9
10
**********MENU**********
1)Add job
2)Delete job
3)Display
Enter your choice
3
job queue is as :
1 2 3 4 5 6 7 8 9 10
Do you want to continue
1. YES
2. NO
1
**********MENU**********
1)Add job
2)Delete job
3)Display
Enter your choice
11
Invalid choice
Do you want to continue
1. YES
2. NO
1
**********MENU**********
1)Add job
2)Delete job
3)Display
Enter your choice
2
1Job deleted
job queue is as :
2 3 4 5 6 7 8 9 10
Do you want to continue
1. YES
2. NO
2
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */

View File

@ -16,7 +16,7 @@ class queue {
int emptyCheck() {
// Check if it's empty
if (front==-1 || front>rear) {
if (front==-1) {
return 1;
}
else {

View 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;
}

View 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()

View File

@ -1,117 +0,0 @@
'''
Problem Statement: In second year computer engineering class, group A student's play cricket, group B students play badminton and group C students play football.
Write a Python program using functions to compute following:
a) List of students who play both cricket and badminton
b) List of students who play either cricket or badminton but not both
c) Number of students who play neither cricket nor badminton
d) Number of students who play cricket and football but not badminton.
(Note- While realising the group, duplicate entries should be avoided, Do not use SET built-in functions)
Code from Data Structure Lab (SPPU - Second Year - Computer Engineering - Content) repository on KSKA Git: https://git.kska.io/sppu-se-comp-codes/DSL
'''
# BEGINNING OF CODE
# List to store players
cricketPlayers = []
badmintonPlayers = []
footballPlayers = []
# Input cricket
def cricketInput():
total = int(input("Total number of CRICKET players:\t"))
for i in range(total):
players = int(input(f"Roll number of player {i+1}:\t"))
cricketPlayers.append(players)
print(f"\n----------\nStudents playing cricket:\t {cricketPlayers}\n----------\n")
# Input badminton
def badmintonInput():
total = int(input("Total number of BADMINTON players:\t"))
for i in range(total):
players = int(input(f"Roll number of player {i+1}:\t"))
badmintonPlayers.append(players)
print(f"\n----------\nStudents playing badminton:\t {badmintonPlayers}\n----------\n")
# Input football
def footballInput():
total = int(input("Total number of FOOTBALL players:\t"))
for i in range(total):
players = int(input(f"Roll number of player {i+1}:\t"))
footballPlayers.append(players)
print(f"\n----------\nStudents playing football:\t {footballPlayers}\n----------\n")
# Playing both cricket and badminton
def CricketAndBadminton():
listCricketAndBadminton = []
for i in cricketPlayers:
if i in badmintonPlayers:
listCricketAndBadminton.append(i)
print(f"\n----------\nStudents playing cricket and badminton:\t {listCricketAndBadminton}\n----------\n")
# Either cricket or badminton but not both
def CricketOrBadminton():
listCricketOrBadminton = []
for i in cricketPlayers:
if i not in badmintonPlayers:
listCricketOrBadminton.append(i)
for i in badmintonPlayers:
if i not in cricketPlayers:
listCricketOrBadminton.append(i)
print(f"\n----------\nStudents playing cricket or badminton (but not both):\t {listCricketOrBadminton}\n----------\n")
# Neither cricket nor badminton, i.e. football only
def FootballOnly():
listCricketAndBadminton = []
listFootballOnly = []
for i in cricketPlayers:
listCricketAndBadminton.append(i)
for i in badmintonPlayers:
if i not in cricketPlayers:
listCricketAndBadminton.append(i)
for i in footballPlayers:
if i not in listCricketAndBadminton:
listFootballOnly.append(i)
print(f"\n----------\nTotal students playing football only are:\t{len(listFootballOnly)}\nList:\t{listFootballOnly}\n----------\n")
# Cricket and football but not badminton
def notBadminton():
listNotBadminton = []
for i in cricketPlayers:
if i in footballPlayers:
if i not in badmintonPlayers:
listNotBadminton.append(i)
print(f"\n----------\nTotal students not playing badminton (but do play cricket and football):\t{len(listNotBadminton)}\nList:\t{listNotBadminton}\n----------\n")
# Main function with options
def main():
print("----- ENTER ROLL NUMBERS IN LIST -----")
cricketInput()
badmintonInput()
footballInput()
print("----- ROLL NUMBERS SAVED -----\n")
while (1):
print("\n----- MAIN MENU -----")
print("1 -> Students playing both cricket and badminton")
print("2 -> Students playing either cricket or badminton, but not both")
print("3 -> Students playing neither cricket nor badminton (i.e. football only)")
print("4 -> Students playing cricket and football, but not badminton")
print("5 -> Exit")
optn = int(input("Choose an option (1-5):\t"))
if (optn == 1):
CricketAndBadminton()
elif (optn == 2):
CricketOrBadminton()
elif (optn == 3):
FootballOnly()
elif (optn == 4):
notBadminton()
elif (optn ==5):
print("\n\n## END OF CODE\n\n")
quit()
else:
print("\n\nPlease choose a valid option (1-5)\n\n")
main()
# END OF CODE

View File

@ -1,141 +0,0 @@
# List to store roll numbers of students that attended the program
programRoll=[]
attendees=int(input("Enter the number of students attending the program:\t"))
# Function to take input for roll numbers in list
def attendInput():
for i in range(attendees):
roll=int(input(f"Enter roll number for student {i+1}:\t"))
programRoll.append(roll)
print(f"Roll numbers of {attendees} students that attended the program are:\t {programRoll}")
# Linear search
def linearSearch(roll_list, roll_search):
for i in roll_list:
if i==roll_search:
return 1
# Sentinel search
def sentinelSearch(roll_list, roll_search, n):
end=roll_list[n-1]
roll_list[n-1]=roll_search
i=0
while (roll_list[i] != roll_search):
i+=1
roll_list[n-1]=end
if ((i<n-1) or (roll_search==roll_list[n-1])):
return 1
else:
return -1
def binarySearch(arr, target):
arr.sort()
# Binary search on the sorted list
low, high = 0, len(arr) - 1
while low <= high:
mid = (low + high) // 2
mid_element = arr[mid]
if mid_element == target:
return mid # Target element found, return its index
elif mid_element < target:
low = mid + 1 # Target is in the right half
else:
high = mid - 1 # Target is in the left half
return -1 # Target element not found in the list
'''
# DOESN'T WORK THIS ONE
# Binary search
def binarySearch(roll_list, roll_search, begin, n):
if begin>n:
return -1
mid=(begin+n)//2
if roll_search==roll_list[mid]:
return mid
if roll_search<roll_list[mid]:
return binarySearch(roll_list, roll_search, begin, mid-1)
else:
return binarySearch(roll_list,roll_search,mid+1,n)
'''
# Fibonacci search
def fibonacciSearch(students_attend, search_element, n):
students_attend.sort()
fibMMm2 = 0
fibMMm1 = 1
fibM = fibMMm2 + fibMMm1
while (fibM<n):
fibMMm2=fibMMm1
fibMMm1=fibM
fibM=fibMMm2+fibMMm1
offset=-1;
while (fibM>1):
i=min(offset+fibMMm2, n-1)
if (students_attend[i]<search_element):
fibM=fibMMm1
fibMMm1=fibMMm2
fibMMm2=fibM-fibMMm1
offset=i
elif (students_attend[i]>search_element):
fibM=fibMMm2
fibMMm1=fibMMm1-fibMMm2
fibMMm2=fibM-fibMMm1
else:
return i
if(fibMMm1 and students_attend[offset+1]==search_element):
return offset+1;
else:
return -1
def main():
# Input for marks and search roll
attendInput()
searchAttendee=int(input("\nEnter the roll number you want to search:\t"))
# Options
while True:
print("\n----- CHOOSE SEARCH TYPE -----")
print("1 -> Linear search")
print("2 -> Sentinel search")
print("3 -> Binary search")
print("4 -> Fibonacci search")
print("5 -> Exit")
optn=int(input("\nChoose an option (1-5):\t"))
if (optn==1):
result=linearSearch(programRoll, searchAttendee)
if (result==1):
print(f"\nRoll number {searchAttendee} attended the program.\n")
else:
print(f"\nRoll number {searchAttendee} has either not been added to the list or was absent.\n")
elif (optn==2):
result=sentinelSearch(programRoll, searchAttendee, attendees)
if (result==1):
print(f"\nRoll number {searchAttendee} attended the program.\n")
else:
print(f"\nRoll number {searchAttendee} has either not been added to the list or was absent.\n")
elif (optn==3):
result=binarySearch(programRoll, searchAttendee)
if (result==-1):
print(f"\nRoll number {searchAttendee} has either not been added to the list or was absent.\n")
else:
print(f"\nRoll number {searchAttendee} attended the program.\n")
elif (optn==4):
result=fibonacciSearch(programRoll, searchAttendee, attendees)
if (result==-1):
print(f"\nRoll number {searchAttendee} has either not been added to the list or was absent.\n")
else:
print(f"\nRoll number {searchAttendee} attended the program.\n")
elif (optn==5):
print("\n## END OF CODE\n\n")
quit()
else:
print("\nPlease choose a valid option (1-5)\n")
main()
# Calling main function
main()

View File

@ -1,61 +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[0:5])
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("\n## END OF CODE\n\n")
quit()
else:
print("\nPlease choose a valid option (1-5).\n")
choose_optn()

View File

@ -1,48 +0,0 @@
# BEGINNING OF CODE
# Function for quick sort:
def quickSort(arr):
if len(arr) <= 1: # if array is empty array
return arr
pivot = arr[len(arr) // 2] # Set pivot element
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]
'''
## ALTERNATIVE WAY OF WRITING THE UPPER 3 LINES (for easy understanding)
left = [] # Empty list to store left part
middle = [] # Empty list to store middle element
right = [] # Empty list to store right part
for i in arr:
if (i < pivot):
left.append(i)
elif (i == pivot):
middle.append(i)
else:
right.append(i)
'''
return quickSort(left) + middle + quickSort(right)
# Function for displaying top scores:
def top5(arr):
top_scores = quickSort(arr)
return top_scores[-1:-6:-1]
# Defining main function:
def main():
percent = [] # List to store percentages
total = int(input("Total number of students are:\t")) # Input for total students
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}\n-----")
print(f"\n-----\nSorted marks (using quick sort algorithm):\t{quickSort(percent)}\n-----")
print(f"\n-----\nTop five scores are:\t{top5(percent)}\n-----")
# Calling main function:
main()
# END OF CODE

View File

@ -1,339 +0,0 @@
#include<iostream>
using namespace std;
class student
{
int roll;
string name;
student *next;
public:
student* create();
void display(student *head);
student* beg_add(student *head);
student* end_add(student *head);
student* btwn_add(student *head);
student* beg_del(student *head);
student* end_del(student *head);
student* btwn_del(student *head);
student* total(student *head);
student* con(student *head,student *head1);
};
student* student::create()
{
int n;
student *head,*p;
head = NULL;
cout<<"Enter number of members: ";
cin>>n;
for(int i = 0; i<n; i++)
{
if(head == NULL)
{
head = new student;
cout<<"\nEnter prn of president: ";
cin>>head->roll;
cout<<"Enter name of president: ";
cin>>head->name;
head->next = NULL;
p = head;
}
else
{
p->next = new student;
p = p->next;
cout<<"\nEnter prn of member: ";
cin>>p->roll;
cout<<"Enter name of member: ";
cin>>p->name;
p->next = NULL;
}
}
return head;
}
void student::display(student *head)
{
student *p;
for(p = head; p->next!= NULL; p = p->next)
{
cout<<p->roll<<" "<<p->name<<"->";
}
cout<<p->roll<<" "<<p->name<<endl;
}
student* student::beg_add(student *head)
{
student *p;
p = new student;
cout<<"\nEnter prn of new president: ";
cin>>p->roll;
cout<<"Enter name of new president: ";
cin>>p->name;
p->next = NULL;
p->next = head;
head = p;
return head;
}
student* student::end_add(student *head)
{
student *p,*q;
p = new student;
cout<<"\nEnter prn of secretary: ";
cin>>p->roll;
cout<<"Enter name of secretary: ";
cin>>p->name;
p->next = NULL;
for(q = head; q->next!=NULL; q = q->next);
q->next = p;
return head;
}
student* student::btwn_add(student *head)
{
int y;
student *p,*q;
p = new student;
cout<<"\nEnter prn of new member: ";
cin>>p->roll;
cout<<"Enter name of new member: ";
cin>>p->name;
cout<<"Enter prn after which new member is to be added: ";
cin>>y;
p->next = NULL;
q = head;
while(q!=NULL)
{
if(q == NULL)
{
cout<<"\nInvalid Data....."<<endl;
}
else if(q->roll == y)
{
p->next = q->next;
q->next = p;
}
q = q->next;
}
return head;
}
student* student::beg_del(student *head)
{
student *p;
p = head;
head = head->next;
delete p;
return head;
}
student* student::end_del(student *head)
{
student *p,*q;
for(q = head; q->next->next!=NULL; q = q->next);
p = q->next;
delete p;
q->next = NULL;
}
student* student::btwn_del(student *head)
{
int y;
student *p,*q;
cout<<"\nEnter prn of member which is to be deleted: ";
cin>>y;
if(head == NULL)
{
cout<<"\nLinked list is empty!!";
return head;
}
p = head;
while(p->next!=NULL)
{
if(p->next->roll==y)
{
q = p->next;
p->next = p->next->next;
delete q;
}
p = p->next;
}
return head;
}
student* student::total(student *head)
{
student *p;
int total = 0;
for(p = head; p!=NULL; p = p->next)
{
total++;
}
cout<<"\nTotal Number of students are: "<<total<<endl;
}
student* student::con(student *head,student *head1)
{
student *p;
for(p = head; p->next!=NULL; p = p->next);
p->next = head1;
return head;
}
int main()
{
int flag = 1;
int flag1 = 1;
int flag2 = 1;
int char0,char1,char2;
student *head,*head1;
student obj;
while(flag)
{
cout<<"\nYOUR CHOICES ARE: ";
cout<<"\n1. LINKED LIST1: \n2. LINKED LIST2: \n3. CONCATENATE LINKED LIST 1 & 2: \n4. EXIT";
cout<<"\nEnter choice: ";
cin>>char0;
switch(char0)
{
case 1:
while(flag1)
{
cout<<"\nWhat operations on list1 would you like to perform?";
cout<<"\n1. Enter prn, name of members: \n2. Add new president: \n3. Add secretary: \n4. Add new members: \n5. Remove president: \n6. Remove secretary: \n7. Remove members: \n8. Total members present: \n9. Exit ";
cout<<"\nEnter choice: ";
cin>>char1;
switch(char1)
{
case 1:
head = obj.create();
obj.display(head);
break;
case 2:
head = obj.beg_add(head);
obj.display(head);
break;
case 3:
head = obj.end_add(head);
obj.display(head);
break;
case 4:
head = obj.btwn_add(head);
obj.display(head);
break;
case 5:
cout<<"\nRemoved president: ";
head = obj.beg_del(head);
obj.display(head);
break;
case 6:
cout<<"\nRemoved secretary: ";
obj.end_del(head);
obj.display(head);
break;
case 7:
head = obj.btwn_del(head);
cout<<"\nMember removed: ";
obj.display(head);
break;
case 8:
obj.total(head);
break;
case 9:
flag1 = 0;
break;
default:
cout<<"\nEnter valid choice!!!";
break;
}
}
break;
case 2:
while(flag2)
{
cout<<"\nWhat operations on list1 would you like to perform?";
cout<<"\n1. Enter prn, name of members: \n2. Add new president: \n3. Add secretary: \n4. Add new members: \n5. Remove president: \n6. Remove secretary: \n7. Remove members: \n8. Total members present: \n9. Exit ";
cout<<"\nEnter choice: ";
cin>>char2;
switch(char2)
{
case 1:
head1 = obj.create();
obj.display(head1);
break;
case 2:
head1 = obj.beg_add(head1);
obj.display(head1);
break;
case 3:
head1 = obj.end_add(head1);
obj.display(head1);
break;
case 4:
head1 = obj.btwn_add(head1);
obj.display(head1);
break;
case 5:
cout<<"\nRemoved president: ";
head1 = obj.beg_del(head1);
obj.display(head1);
break;
case 6:
cout<<"\nRemoved secretary: ";
obj.end_del(head1);
obj.display(head1);
break;
case 7:
head1 = obj.btwn_del(head1);
cout<<"\nMember removed: ";
obj.display(head1);
break;
case 8:
obj.total(head1);
break;
case 9:
flag2 = 0;
break;
default:
cout<<"\nEnter valid choice!!!";
break;
}
}
break;
case 3:
head = obj.con(head,head1);
obj.display(head);
break;
case 4:
flag = 0;
break;
default:
cout<<"\nEnter valid choice: ";
break;
}
}
return 0;
}

View File

@ -1,97 +0,0 @@
'''
Problem Statement: Write a Python program to store marks scored in subject Fundamental of Data Structure by N students in the class. Write functions to compute following:
a) The average score of class
b) Highest score and lowest score of class
c) Count of students who were absent for the test
d) Display mark with highest frequency
Code from Data Structure Lab (SPPU - Second Year - Computer Engineering - Content) repository on KSKA Git: https://git.kska.io/sppu-se-comp-codes/DSL
'''
# BEGINNING OF CODE
# List for storing marks
marks = []
total = int(input("Total number of students are:\t"))
# Input marks
def marksInput():
print("\n----------\nNOTE: PLEASE ENTER MARKS OUT OF 50. ENTER '-1' FOR ABSENT STUDENTS.\n----------\n")
for i in range(total):
enterMarks = int(input(f"Enter marks for student {i+1}:\t"))
marks.append(enterMarks)
print(f"\n-----\nMarks of {total} students are:\t{marks}\n-----")
# Option 1 = Average score
def average_marks():
marks_withoutAbsent = []
for i in marks:
if (i >= 0):
marks_withoutAbsent.append(i)
else:
continue
average_calc = sum(marks_withoutAbsent) / total
print(f"\n------\nAverage score of {total} students is:\t{average_calc}\n-----")
# Option 2 = High and low marks
def high_low():
maxi = marks[0] # Initialise maxi with the first element of the marks list
mini = marks[0] # Initialise mini with the first element of the marks list
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(f"\n-----\nHighest score is:\t{maxi}\nLowest score is:\t{mini}\n-----")
# Option 3 = Absent count
def absent():
absent_count = 0;
for i in marks:
if (i < 0):
absent_count+=1
else:
continue
print(f"\n-----\nTotal absent students are:\t{absent_count}\n-----")
# Option 4 = Highest frequency
def high_freq():
freq_count = 0 # Initialise frequency counter
for i in range(len(marks)): # Iterate through marks list using i
if (marks[i] >= 0): # Only consider non-negative marks (since -1 is absent)
temp_count = 0 # Initialise temporary counter
for j in range(len(marks)): # Iterate through marks list using j again
if (marks[i] == marks[j]):
temp_count+=1
if (freq_count < temp_count): # If temp_count is greater than freq_count value, then
freq_count = temp_count # Make freq_count equal to temp_count
print(f"\n-----\nHighest frequency is:\t{freq_count}\n-----")
def main():
marksInput()
while (1):
print("\n----- MAIN MENU -----")
print("1 -> Average score of class")
print("2 -> Highest and lowest score of class")
print("3 -> Total absent students")
print("4 -> Marks with highest frequency")
print("5 -> Exit")
optn = int(input("Choose an option (1-5):\t"))
if (optn == 1):
average_marks()
elif (optn == 2):
high_low()
elif (optn == 3):
absent()
elif (optn == 4):
high_freq()
elif (optn == 5):
print("\n\n## END OF CODE\n\n")
quit()
else:
print("\n\nPlease choose a valid option (1-5)\n\n")
main()
# END OF CODE

View File

@ -1,240 +0,0 @@
/*
The ticket booking system of Cinemax theater has to
be implemented using C++ program.
There are 10 rows and 7 seats in each row. Doubly
circular linked list has to be maintained
to keep track of free seats at rows. Assume some
random booking to start with. Use array to store
pointers (Head pointer) to each row. On demand
a) The list of available seats is to be displayed
b) The seats are to be booked
c) The booking can be cancelled
*/
#include <iostream>
#include<stdlib.h>
using namespace std;
class node
{ public:
node* next;
node* prev;
int seat;
string id;
int status;
};
class cinemax
{
public:
node* head,* tail ,* temp;
cinemax()
{
head=NULL;
}
void create_list();
void display();
void book();
void cancel();
void avail();
};
void cinemax::create_list()
{
int i=1;
temp=new node;
temp->seat=1;
temp->status=0;
temp->id="null";
tail=head=temp;
for(int i=2;i<=70;i++)
{
node *p;
p= new node;
p->seat=i;
p->status=0;
p->id="null";
tail->next=p;
p->prev=tail;
tail=p;
tail->next=head;
head->prev=tail;
}
}
void cinemax::display()
{
{ int r=1;
node* temp;
temp=head;
int count=0;
cout<<"\n------------------------------------------------------------------------------------\n";
cout<<" Screen this way \n";
cout<<"------------------------------------------------------------------------------------\n";
while(temp->next!=head)
{
if(temp->seat/10==0)
cout<<"S0"<<temp->seat<<" :";
else
cout<<"S"<<temp->seat<<" :";
if(temp->status==0)
cout<<"|___| ";
else
cout<<"|_B_| ";
count++;
if(count%7==0)
{
cout<<endl;
r++;
}
temp=temp->next;
}
cout<<"S"<<temp->seat<<" :";
if(temp->status==0)
cout<<"|___| ";
else
cout<<"|_B_| ";
}
}
void cinemax::book()
{ int x;
string y;
label:
cout<<"\n\n\nEnter seat number to be booked\n";
cin>>x;
cout<<"Enter your ID number\n";
cin>>y;
if(x<1||x>70)
{
cout<<"Enter correct seat number to book (1-70)\n";
goto label;
}
node *temp;
//temp=new node;
temp=head;
while(temp->seat!=x)
{
temp=temp->next;
}
if(temp->status==1)
cout<<"Seat already booked!\n";
else{
temp->status=1;
temp->id=y;
cout<<"Seat "<<x<<" booked!\n";
}
}
void cinemax::cancel()
{
int x;
string y;
label1:
cout<<"Enter seat number to cancel booking\n";
cin>>x;
cout<<"Enter you ID\n";
cin>>y;
if(x<1||x>70)
{
cout<<"Enter correct seat number to cancel (1-70)\n";
goto label1;
}
node *temp;
//temp=new node;
temp=head;
while(temp->seat!=x)
{
temp=temp->next;
}
if(temp->status==0)
{
cout<<"Seat not booked yet!!\n";
}
else
{
if(temp->id==y)
{
temp->status=0;
cout<<"Seat Cancelled!\n";
}
else
cout<<"Wrong User ID !!! Seat cannot be cancelled!!!\n";
}
}
void cinemax::avail()
{
int r=1;
node* temp;
temp=head;
int count=0;
cout<<"\n\n\n\n";
cout<<"\n------------------------------------------------------------------------------------\n";
cout<<" Screen this way \n";
cout<<"------------------------------------------------------------------------------------\n";
while(temp->next!=head)
{
{
if(temp->seat/10==0)
cout<<"S0"<<temp->seat<<" :";
else
cout<<"S"<<temp->seat<<" :";
if(temp->status==0)
cout<<"|___| ";
else if(temp->status==1)
cout<<" ";
count++;
if(count%7==0)
{
cout<<endl;
}
}
temp=temp->next;
}
if(temp->status==0)
{
cout<<"S"<<temp->seat<<" :";
if(temp->status==0)
cout<<"|___| ";
}
}
int main()
{ cinemax obj;
obj.create_list();
int ch;
char c='y';
while(c=='y')
{ obj.display();
cout<<"\n*********************************************\n";
cout<<" CINEMAX MOVIE THEATRE\n";
cout<<"*********************************************\n";
cout<<"\nEnter Choice\n1.Current SeatStatus\n2.Book Seat \n3.Available Seat\n4.CancelSeat\n";
cin>>ch;
switch(ch)
{
case 1:obj.display();
break;
case 2: obj.book();
break;
case 3:obj.avail();
break;
case 4: obj.cancel();
break;
default: cout<<"Wrong choice input\n";
}
cout<<"\nDo you want to perform any other operation : (y/n)\n";
cin>>c;
}
return 0;
}

View File

@ -1,192 +0,0 @@
#include<iostream>
using namespace std;
class stack1
{
int top;
char stack2[100];
char infix[100];
public:
stack1()
{
top = -1;
}
void infix1();
void check();
int check1(char tkn);
void push(int x);
int pop();
bool isEmpty();
bool isFull();
void display();
};
bool stack1::isEmpty()
{
if(top == -1)
{
return true;
}
else
{
return false;
}
}
bool stack1::isFull()
{
if(top == 100 - 1)
{
return true;
}
else
{
return false;
}
}
void stack1::push(int x)
{
if(!isFull())
{
top++;
stack2[top] = x;
}
else
{
cout<<"Stack is full!!\n";
}
}
int stack1::pop()
{
int x;
if(!isEmpty())
{
x = stack2[top];
top--;
return x;
}
else
{
cout<<"Stack is empty!!\n";
}
}
int stack1::check1(char tkn)
{
if(isEmpty())
{
return 0;
}
if(stack2[top] == '(')
{
if(tkn == ')')
{
return 1;
}
else
{
return 0;
}
}
if(stack2[top] == '{')
{
if(tkn == '}')
{
return 1;
}
else
{
return 0;
}
}
if(stack2[top] == '[')
{
if(tkn == ']')
{
return 1;
}
else
{
return 0;
}
}
}
void stack1::check()
{
char tkn;
int x = 0;
for(int i = 0; infix[i]!='\0'; i++)
{
tkn = infix[i];
if(tkn == '('||tkn == ')'||tkn == '['||tkn == ']'||tkn == '{'||tkn == '}')
{
if(tkn == '('||tkn == '['||tkn == '{')
{
push(tkn);
}
if(tkn == '}'||tkn == ']'||tkn == ')')
{
x = check1(tkn);
if(x == 1)
{
pop();
}
else
{
push(tkn);
break;
}
}
}
}
if(!isEmpty())
{
cout<<"Equation is not paranthesized!!\n";
}
else
{
cout<<"Equation is paranthesized!!\n";
}
}
void stack1::infix1()
{
cout<<"\nEnter infix expression(end expression with '#'): ";
for(int i = 0; i < 100; i++)
{
cin>>infix[i];
if(infix[i] == '#')
{
infix[i] = '\0';
break;
}
}
}
void stack1::display()
{
for(int i = 0; infix[i]!= '\0'; i++)
{
cout<<infix[i];
}
cout<<"\n";
}
int main()
{
int ch = 0;
do
{
stack1 obj;
obj.infix1();
obj.display();
obj.check();
cout<<"\nDO YOU WANT TO CHECK ANOTHER EXPRESSION?\n";
cout<<"1. YES \n2. NO \n";
cin>>ch;
}while(ch == 1);
return 0;
}

View File

@ -1,111 +0,0 @@
#include<iostream>
#include<ctype.h>
using namespace std;
class stack
{
int top;
char data[20];
public:
stack()
{
top=-1;
}
void conversion(char infix[20],char postfix[20])
{
int j=0,i;
char e,token,x;
for(i=0;infix[i]!='\0';i++)
{
token=infix[i];
if(isalnum(token))
{
postfix[j]=token;
j++;
}
else
{
if(token=='(')
push(token);
else if(token==')')
{
while((x=pop())!='(')
{
postfix[j]=x;
j++;
}
}
else
{
e=topmost();
while(precedence(token)<=precedence(e) && !empty())
{
x=pop();
postfix[j]=x;
j++;
}
push(token);
}
}
}
while(!empty())
{
x=pop();
postfix[j]=x;
j++;
}
postfix[j]='\0';
}
void push(int x)
{
top++;
data[top]=x;
}
int pop()
{
char x;
x=data[top];
top--;
return x;
}
char topmost()
{
char e;
e=data[top];
return e;
}
int precedence(char x)
{
if(x=='(')
return 0;
if(x=='+'|| x=='-')
return 1;
if(x=='*'|| x=='/' ||x=='%')
return 2;
else
return 3;
}
int empty()
{
if(top==-1)
return 1;
else
return 0;
}
};
int main()
{
stack s;
char infix[20],postfix[20];
cout<<"Enter the infix expression: ";
cin>>infix;
s.conversion(infix,postfix);
cout<<"Post fix expression is: "<<postfix;
return 0;
}

View File

@ -1,172 +0,0 @@
#include<iostream>
using namespace std;
class deque1
{
public:
int f,r,data[100],n;
deque1()
{
f = r = -1;
cout<<"Enter number of elements: ";
cin>>n;
}
void enqueuef();
void enqueuer();
void dequeuef();
void dequeuer();
bool isEmpty();
bool isFull();
void display();
};
void deque1::enqueuef()
{
int id;
cout<<"\nEnter element: ";
cin>>id;
if(!isFull())
{
if(f == -1)
f = r = 0;
else if(f == 0)
f = n - 1;
else
f--;
data[f] = id;
}
else
cout<<"\nQueue is full....\n";
}
void deque1::enqueuer()
{
int id;
cout<<"\nEnter element: ";
cin>>id;
if(!isFull())
{
if(f == -1)
f = r = 0;
else if(r == n - 1)
r = 0;
else
r++;
data[r] = id;
}
else
cout<<"\nQueue is full....\n";
}
void deque1::dequeuef()
{
if(!isEmpty())
{
if(f == r)
f = r = -1;
else if(f == n-1)
f = 0;
else
f++;
}
else
cout<<"\nQueue is empty....\n";
}
void deque1::dequeuer()
{
if(!isEmpty())
{
if(f == r)
f = r = -1;
else if(r == 0)
r = n-1;
else
r--;
}
else
cout<<"\nQueue is empty....\n";
}
void deque1::display()
{
int i;
cout<<"\nDeque: ";
if(!isEmpty())
{
i = f;
do
{
cout<<data[i]<<" ";
i = (i+1)%n;
}while(i != (r+1)%n);
}
else
cout<<"\nQueue is empty....\n";
cout<<"\n";
}
bool deque1::isFull()
{
if((f==0 && r >= n - 1)|| f==r+1)
return true;
else
return false;
}
bool deque1::isEmpty()
{
if(r == -1)
return true;
else
return false;
}
int main()
{
deque1 obj;
int ch;
bool flag = true;
while(flag)
{
cout<<"\n****YOUR CHOICES ARE****\n";
cout<<"\n1. Enqueue(at front) \n2. Enqueue(at rear) \n3. Dequeue(at front) \n4. Dequeue(at rear) \n5. Display queue \n6. Exit";
cout<<"\nEnter your choice: ";
cin>>ch;
switch(ch)
{
case 1:
obj.enqueuef();
obj.display();
break;
case 2:
obj.enqueuer();
obj.display();
break;
case 3:
obj.dequeuef();
obj.display();
break;
case 4:
obj.dequeuer();
obj.display();
break;
case 5:
obj.display();
break;
case 6:
flag = false;
break;
default:
cout<<"\nEnter valid choice!!!\n";
break;
}
}
return 0;
}

View File

@ -1,125 +0,0 @@
#include <iostream>
using namespace std;
#define size 5
class pizza
{
int porder[size];
int front, rear;
public:
pizza()
{
front = rear = -1;
}
int qfull()
{
if (front == (rear + 1) % size)
return 1;
else
return 0;
}
int qempty()
{
if (front == -1)
return 1;
else
return 0;
}
void accept_order(int item)
{
if (qfull())
cout << "\nVery Sorry !!!! No more orders....\n";
else
{
if (front == -1)
{
front = rear = 0;
}
else
{
rear = (rear + 1) % size;
}
porder[rear] = item;
}
}
void make_payment(int n)
{
int item;
char ans;
if (qempty())
cout << "\nSorry !!! order is not there...\n";
else
{
cout << "\nDeliverd orders as follows...\n";
for (int i = 0; i < n; i++)
{
item = porder[front];
if (front == rear)
{
front = rear = -1;
}
else
{
front = (front + 1) % size;
}
cout << "\t" << item;
}
cout << "\nTotal amount to pay : " << n * 100;
cout << "\nThank you visit Again....\n";
}
}
void order_in_queue()
{
int temp;
if (qempty())
{
cout << "\nSorry !! There is no pending order...\n";
}
else
{
temp = front;
cout << "\nPending Order as follows..\n";
while (temp != rear)
{
cout << "\t" << porder[temp];
temp = (temp + 1) % size;
}
cout << "\t" << porder[temp];
}
}
};
int main()
{
pizza p1;
int ch, k, n;
do
{
cout << "\n\t***** Welcome To Pizza Parlor *******\n";
cout << "\n1.Accept order\n2.Make_payment\n3.Pending Orders\nEnter u r choice:";
cin >> ch;
switch (ch)
{
case 1:
cout << "\nWhich Pizza would do u like to have today\n";
cout << "\n1.Veg Soya Pizza\n2.Veg butter Pizza\n3.Egg_Pizza";
cout << "\nPlease enter your order: ";
cin >> k;
p1.accept_order(k);
break;
case 2:
cout << "\nHow many Pizza ?";
cin >> n;
p1.make_payment(n);
break;
case 3:
cout << "\n Following orders are in queue to deliver....as follows..\n";
p1.order_in_queue();
break;
}
} while (ch != 4);
return 0;
}

View File

@ -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.

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.

View File

@ -1,133 +0,0 @@
#include<iostream>
using namespace std;
#define SIZE 20
class dequeue
{
int a[20],f,r;
public:
dequeue();
void insert_at_beg(int);
void insert_at_end(int);
void delete_fr_front();
void delete_fr_rear();
void show();
};
dequeue::dequeue()
{
f=-1;
r=-1;
}
void dequeue::insert_at_end(int i)
{
if(r>=SIZE-1)
cout<<"insertion is not possible, overflow!!!!";
else
{
if(f==-1)
{
f++;
r++;
}
else
r=r+1;
a[r]=i;
cout<<"Inserted item is"<<a[r];
}
}
void dequeue::insert_at_beg(int i) {
if(f==-1) {
f=0;
a[++r]=i;
cout<<" inserted element is:"<<i;
}
else if(f!=0)
{
a[--f]=i;
cout<<" inserted element is:"<<i;
}
else {
cout<<" insertion is not possible, overflow!!!";
}
}
void dequeue::delete_fr_front() {
if(f==-1) {
cout<<"deletion is not possible::dequeue is empty";
return;
}
else {
cout<<"the deleted element is:"<<a[f];
if(f==r) {
f=r=-1;
return;
} else
f=f+1;
}
}
void dequeue::delete_fr_rear() {
if(f==-1) {
cout<<"deletion is not possible::dequeue is empty";
return;
}
else {
cout<<"the deleted element is:"<<a[r];
if(f==r) {
f=r=-1;
} else
r=r-1;
}
}
void dequeue::show() {
if(f==-1) {
cout<<"Dequeue is empty";
} else {
for(int i=f;i<=r;i++) {
cout<<a[i]<<" ";
}
}
}
int main()
{
int c,i;
dequeue d;
do//perform switch opeartion
{
cout<<" 1.insert at beginning";
cout<<" 2.insert at end";
cout<<" 3.show";
cout<<" 4.deletion from front";
cout<<" 5.deletion from rear";
cout<<" 6.exit";
cout<<" enter your choice:";
cin>>c;
switch(c)
{
case 1:
cout<<"enter the element to be inserted";
cin>>i;
d.insert_at_beg(i);
break;
case 2:
cout<<"enter the element to be inserted";
cin>>i;
d.insert_at_end(i);
break;
case 3:
d.show();
break;
case 4:
d.delete_fr_front();
break;
case 5:
d.delete_fr_rear();
break;
default:
cout<<"invalid choice";
break;
}
}while(c!=7);
return 0;
}

Binary file not shown.

View File

@ -1,158 +0,0 @@
#include<iostream>
#include<string>
#define N 20
#define SERIOUS 10
#define NONSERIOUS 5
#define CHECKUP 1
using namespace std;
string Q[N];
int Pr[N];
int r = -1,f = -1;
void enqueue(string data,int p)//Enqueue function to insert data and its priority in queue
{
int i;
if((f==0)&&(r==N-1)) //Check if Queue is full
cout<<"Queue is full";
else
{
if(f==-1)
{ //if Queue is empty
f = r = 0;
Q[r] = data;
Pr[r] = p;
}
else if(r == N-1)
{ //if there there is some elemets in Queue
for(i=f;i<=r;i++)
{
Q[i-f] = Q[i];
Pr[i-f] = Pr[i];
r = r-f;
f = 0;
for(i = r;i>f;i--)
{
if(p>Pr[i])
{
Q[i+1] = Q[i];
Pr[i+1] = Pr[i];
}
else break;
Q[i+1] = data;
Pr[i+1] = p;
r++;
}
}
}
else
{
for(i = r;i>=f;i--)
{
if(p>Pr[i])
{
Q[i+1] = Q[i];
Pr[i+1] = Pr[i];
}
else break;
}
Q[i+1] = data;
Pr[i+1] = p;
r++;
}
}
}
void print() { //print the data of Queue
int i;
for(i=f;i<=r;i++) {
cout << "Patient's Name - "<<Q[i];
switch(Pr[i]) {
case 1:
cout << " Priority - 'Checkup' " << endl;
break;
case 5:
cout << " Priority - 'Non-serious' " << endl;
break;
case 10:
cout << " Priority - 'Serious' " << endl;
break;
default:
cout << "Priority not found" << endl;
}
}
}
void dequeue() { //remove the data from front
if(f == -1)
{
cout<<"Queue is Empty";
}
else
{
cout<<"deleted Element ="<<Q[f]<<endl;
cout<<"Its Priority = "<<Pr[f]<<endl;
if(f==r) f = r = -1;
else f++;
}
}
int main()
{
string data;
int opt,n,i,p;
cout<<"Enter Your Choice:-"<<endl;
do {
cout << "\n 1 : Insert the Data in Queue" << endl << "2: Display the Queue " << endl << "3: Delete the data from the Queue"
<< endl << "0 for Exit"<< endl;
cin >> opt;
switch(opt) {
case 1:
cout << "Enter the number of Patient" << endl;
cin >> n;
i = 0;
while(i < n) {
cout << "Enter your name of the patient : ";
cin >> data;
ifnotdoagain:
cout << "Enter your Priority (0: serious, 1: non-serious, 2: general checkup) : ";
cin >> p;
switch(p) {
case 0:
enqueue(data,SERIOUS);
break;
case 1:
enqueue(data,NONSERIOUS);
break;
case 2:
enqueue(data,CHECKUP);
break;
default:
goto ifnotdoagain;
}
i++;
}
break;
case 2:
print();
break;
case 3:
dequeue();
break;
case 0:
cout << "Bye Bye !" << endl;
break;
default:
cout<<"Incorrect Choice"<<endl;
}
}while(opt!=0);
return 0;
}

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

Binary file not shown.