0% found this document useful (0 votes)
13 views

Job Queue.cpp (1)

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

Job Queue.cpp (1)

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

#include <iostream>

#include <queue>

using namespace std;

class Queue {

private:

int item[100];

int front;

int rear;

public:

Queue() {

front = -1;

rear = -1;

void enqueue(int val);

void dequeue();

void show();

bool isEmpty();

bool isFull();

};

bool Queue::isEmpty() {

if (front == -1) {

return true;

} else {

return false;

bool Queue::isFull() {
if (rear == 100 - 1) {

return true;

} else {

return false;

void Queue::enqueue(int val) {

if (isFull()) {

cout << "Queue is full" << endl;

} else {

if (front == -1) {

front = 0;

rear++;

item[rear] = val;

void Queue::dequeue() {

if (isEmpty()) {

cout << "Queue is empty" << endl;

} else {

if (front == rear) {

front = -1;

rear = -1;

} else {

front++;

}
void Queue::show() {

if (!this->isEmpty()) {

cout << "The queue is: ";

for (int i = front; i <= rear; i++) {

cout << item[i] << " ";

cout << endl;

int main() {

Queue q;

cout << "1. Enqueue" << endl;

cout << "2. Dequeue" << endl;

cout << "3. Show" << endl;

cout << "4. Exit" << endl;

int choice;

cout << "Enter your choice: ";

cin >> choice;

while (choice != 4) {

switch (choice) {

case 1: {

int val;

cout << "Enter the value to be enqueued: ";

cin >> val;

q.enqueue(val);

break;

case 2: {

q.dequeue();
break;

case 3: {

q.show();

break;

default: {

cout << "Invalid choice" << endl;

cout << "Enter your choice: ";

cin >> choice;

You might also like