pq.c
-------------------------------------
#Define pq.h
class pq
{
int a[SIZE];
int front;
int rear;
public:
pq();
~pq();
void push(int i);
int pop();
int isempty();
int isfull();
};
pq::pq()
{
front=0;
rear=0;
}
pq::~pq()
{
delete []a;
}
void pq::push(int i)
{
if(isfull())
{
cout<<"Queue is FULL !!!No insertion allowed
further";
return;
}
a[rear] = i;
rear++;
}
int pq::pop()
{
if(isempty())
{
cout<<"Queue Empty !!!Value returned will be
garbage";
return (-9999);
}
return(a[front++]);
}
int queue::isempty()
{
if(front == rear)
return 1;
else
return 0;
}
int queue::isfull()
{
if(rear == SIZE)
return 1;
else
return 0;
}
main.c
------------------------------------------------------------------
# include<iostream.h>
# include<conio.h>
#include<pq.h>
void main()
{
int ch;
pq queue;
while(1)
{
cout <<"\n1.push 2.pop 3.exit\nEnter ur choice";
cin >> ch;
switch(ch)
{
case 1: cout <<"enter the element";
cin >> ch;
queue.push(ch);
break;
case 2: queue.pop(); break;
case 3: exit(0);
}
}
return (0);
}
Get Answers For Free
Most questions answered within 1 hours.