#include<iostream.h>
#include<conio.h>
class queue
{
private:
int rear,front,q[10],ele,i;
public:
queue()
{
rear=-1;
front=0;
}
void insert(int);
int delet();
void disp();
};
void queue::insert(int ele)
{
if(rear<=9)
{
rear=rear+1;
q[rear]=ele;
}
else
{
cout<<"Queue is full"<<endl;
}
}
int queue::delet()
{
if(front==-1)
{
cout<<"Queue is empty"<<endl;
}
else
ele=q[front];
front=front+1;
return(ele);
}
void queue::disp()
{
if(front==-1)
{
cout<<"Queue is empty";
}
else
{
cout<<"\nQueue is:";
}
for(int i=front;i<=rear;i++)
{
cout<<q[i];
}
cout<<endl;
}
void main()
{
queue q;
clrscr();
q.insert(4);
q.insert(5);
q.insert(6);
q.insert(7);
q.insert(8);
q.disp();
int b=q.delet();
cout<<"\nDeleted element is:"<<b<<endl;
cout<<"\nQueue after deleting element:"<<endl;
q.disp();
getch();
}
#include<iostream.h>
#include<conio.h>
class queue
{
private:
int rear,front,q[10],ele,i;
public:
queue()
{
rear=-1;
front=0;
}
void insert(int);
int delet();
void disp();
};
void queue::insert(int ele)
{
if(rear<=9)
{
rear=rear+1;
q[rear]=ele;
}
else
{
cout<<"Queue is full"<<endl;
}
}
int queue::delet()
{
if(front==-1)
{
cout<<"Queue is empty"<<endl;
}
else
ele=q[front];
front=front+1;
return(ele);
}
void queue::disp()
{
if(front==-1)
{
cout<<"Queue is empty";
}
else
{
cout<<"\nQueue is:";
}
for(int i=front;i<=rear;i++)
{
cout<<”\t”<<q[i];
}
cout<<endl;
}
void main()
{
queue q;
clrscr();
q.insert(4);
q.insert(5);
q.insert(6);
q.insert(7);
q.insert(8);
q.disp();
int b=q.delet();
cout<<"\nDeleted element is:"<<b<<endl;
cout<<"\nQueue after deleting element:"<<endl;
q.disp();
getch();
}
Sign up here with your email
ConversionConversion EmoticonEmoticon