moved assignment-29_test2kska.cpp to archive since it has been merged with the main branch
This commit is contained in:
parent
048bb1f136
commit
4f4565f5af
@ -1,132 +0,0 @@
|
||||
#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