Added assignment 29 (queue job)
This commit is contained in:
parent
89ab20f71c
commit
6b6c0d1b9c
@ -15,7 +15,12 @@ In this repository, you'll find codes for Data Structure Lab.
|
|||||||
5. [DSL - Assignment 5 (String)](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/assignment-5.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_
|
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)
|
14. [DSL - Assignment 14 (Selection, Bubble Sorting)](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/assignment-14.py)
|
||||||
|
<<<<<<< HEAD
|
||||||
16. [DSL - Assignment 16 (Quick sort)](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/assignment-16.cpp)
|
16. [DSL - Assignment 16 (Quick sort)](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/assignment-16.cpp)
|
||||||
|
=======
|
||||||
|
16. [DSL - Assignment 16 (Quick sort)](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/assignment-16.py)
|
||||||
|
29. [DSL - Assignment 29 (Queue Job)](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/main/assignment-29.py)
|
||||||
|
>>>>>>> fc6d144 (Added link for assignment-29 to README)
|
||||||
|
|
||||||
### Write-ups
|
### Write-ups
|
||||||
|
|
||||||
@ -52,9 +57,7 @@ In this repository, you'll find codes for Data Structure Lab.
|
|||||||
> These are the codes we're working on. They *may not work* the way intended.
|
> 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).
|
> 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).
|
||||||
|
|
||||||
[quicksortEarlyAccess.py](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/testing/quicksortEarlyAccess.py)
|
**ALL TESTING CODES HAVE BEEN MERGED IN THE MAIN BRANCH.**
|
||||||
|
|
||||||
[assignment-29 (Early access).cpp](https://git.kska.io/sppu-se-comp-codes/DSL/src/branch/testing/assignment-29%20%28Early%20access%29.cpp)
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
132
assignment-29.cpp
Normal file
132
assignment-29.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;
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user