Untitled

 avatar
user_7016102
plain_text
a month ago
1.5 kB
5
Indexable
Never
//wap to implement the disadvantages of linear queue 

#include<iostream>
#include<stdlib.h>
using namespace std;

int queue[100], front = -1, n, rear = -1;

void enqueue(int val)
{
	if(rear>=n-1)
	{
		cout<<"Enqueue is not allowed"<<endl;
	}
	else{
		rear++;
		queue[rear] = val;
		front = 0;
	}
}

void dequeue()
{
	if(front<=-1)
	{
		cout<<"Queue is empty"<<endl;
	}
	else {
		cout<<"The dequeued element is :"<<queue[front]<<endl;
		front++;
		
	}
}
void display()
{
	if(front>=0)
	{
		cout<<"The queue elements are :"<<endl;
		for(int i=front;i<=rear ;i++)
		{
			cout<<queue[i]<<" ";
			cout<<endl;
		}
	}
	else{
		cout<<"Queue is empty"<<endl;
	}
}




int main()
{
	cout<<"Enter value of size"<<endl;
	cin>>n;
	int ch,val;
	cout<<"1) To Enqueue Data"<<endl;
	cout<<"2) To Dequeue Data"<<endl;
	cout<<"3) To Display Data"<<endl;
	cout<<"4) To Exit Data"<<endl;
	do
	{
		cout<<"Enter choice"<<endl;
		cin>>ch;
		switch(ch) {
         case 1: {
            cout<<"Enter value to be enqueued:"<<endl;
            cin>>val;
            enqueue(val);
            break;
         }
         case 2: {
            dequeue();
            break;
         }
         case 3: {
            display();
            break;
         }
         case 4: {
            cout<<"Exit"<<endl;
            break;
         }
         default: {
            cout<<"Invalid Choice"<<endl;
         }
	}
}	while(ch!=4);
return 0;

}
Leave a Comment