0% found this document useful (0 votes)
2 views5 pages

Circular Queue Code

This document contains a C++ program that implements a circular queue with functionalities for insertion, deletion, and display of elements. The program prompts the user to choose an action from a menu and handles overflow and underflow conditions. It is designed to run in a console environment and continuously accepts user input until the exit option is selected.

Uploaded by

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

Circular Queue Code

This document contains a C++ program that implements a circular queue with functionalities for insertion, deletion, and display of elements. The program prompts the user to choose an action from a menu and handles overflow and underflow conditions. It is designed to run in a console environment and continuously accepts user input until the exit option is selected.

Uploaded by

jawad arshad
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

LAB PROGRAM 1/NOV 2023

Name Jawad Arshad


ID F2022065258
#include <iostream>

using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input
loop */

int C[5],S=5,R=-1,F=-1;

void insert(int value)

if (F==0 && R==S-1 || F==R+1)

cout<<"Overflow "<<endl;

else if(F==-1) // its mean first timed insertion

F=R=0;

C[R]=value;

cout<<C[R]<<" Value to be pushed"<<endl;

else if (R==S-1) // F>0; also add in this conditiojn

R=0;

C[R]=value;

cout<<C[R]<<" Value to be pushed"<<endl;

else

C[++R]=value;
cout<<value<<" Value to be pushed"<<endl;

void deletion ()

if (F==-1)

cout<<"Under flow"<<endl;

else if (F==R)

F=R=-1;

else if (F==S-1) // R>=o

F=0;

else

F=F+1;

void display()

if (F<=R)

for (int i=F; i<=R; i++)

cout<<C[i]<<" "<<endl;

}
}

else

for (int i=F; i<S; i++)

cout<<C[i]<<" "<<endl;

for (int i=0; i<=R; i++)

cout<<C[i]<<endl;

int main(int argc, char** argv)

while (true)

int choice,value;

cout<<"........Queue Menu........"<<endl;

cout<<"Press 1 for insert data in Queue."<<endl;

cout<<"Press 2 for remove data in Queue."<<endl;

cout<<"Press 3 for display data in Queue."<<endl;

cout<<"Press 4 for exit."<<endl;

cout<<".........Enter your choice........"<<endl;

cin>>choice;

switch(choice)

case 1:
{

cout<<"Enter value to be push."<<endl;

cin>>value;

insert(value);

break;

case 2:

deletion();

break;

case 3:

display();

break;

case 4:

cout<<"Exiting the program."<<endl;

return 0;

default:

cout<<"Invalid number."<<endl;

break;

return 0;

You might also like