0% found this document useful (0 votes)
5 views2 pages

E 32 Aaryan

Uploaded by

randiveaaryan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

E 32 Aaryan

Uploaded by

randiveaaryan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

#define size 5
using namespace std;

class Queue {
public:
int arr[size];
int f = -1, r = -1;
bool isempty() { return (f == -1) ? true : false; }

bool isfull() { return ((r + 1) % size == f) ? true : false; }

void enqueue(int val) {


if (isfull()) {
cout << "Queue is full" << endl;
} else {
if (f == -1) {
f++;
r++;
arr[r] = val;
} else {
r = (r + 1) % size;
arr[r] = val;
}
}
}

void dequeue() {
if (isempty()) {
cout << "Queue is empty" << endl;
} else if (f == r) {
cout << arr[f] << " has been deleted." << endl;
f = r = -1;
} else {
cout << arr[f] << " has been deleted." << endl;
f = (f + 1) % size;
}
}

void display() {
int temp = f;
if (isempty()) {
cout << "Order list is empty." << endl;
} else {
while (temp != r) {
cout << arr[temp] << " ";
temp = (temp + 1) % size;
}
cout << arr[temp] << endl;
}
}
};

int main() {
int ch;
Queue que;
do {
cout << "MENU" << endl;
cout << "1.Add order" << endl;
cout << "2.Remove order" << endl;
cout << "3.Display remaining orders" << endl;
cout << "4.Exit" << endl;
cout << "Enter your choice:";
cin >> ch;
switch (ch) {
case 1:
if (que.isfull()) {
cout << "Queue is full" << endl;
break;
}
int val;
cout << "Enter element you want to add:";
cin >> val;
que.enqueue(val);
break;
case 2:
que.dequeue();
break;
case 3:
que.display();
break;
case 4:
cout << "Thank you" << endl;
break;
default:
cout << "Enter valid choice" << endl;
break;
}
} while (ch != 4);
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy