Note:no funtions are used
kindly help me in Urgent !
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
srikiran GPosted Jan 3, 2013, 7:47 AM
#include
#include
#define max 5
using namespace std;
class queue
//I am Stack also here
{
int front;
int rear;
int data[max];
public:
queue()
{
front = 0;
rear = 0;
}
void enQueue(int i)
{
if( rear == max )
return ;
data[rear++] = i;
}
int deQueue()
{
if( front == rear )
{
return -1;
}
return data[front++];
}
void disp()
{
cout<<"Front ="<
class stack
{
queue q;
public:
void push( int i)
{
if( q.size() == max )
{
cout<<"Stack is full"<
return ;
}
q.enQueue(i);
}
int pop()
{
int ret = 0;
int result = 0;
queue temp;
int c = 0;
while( ( ret = q.deQueue() ) != -1)
{
temp.enQueue(ret);
result = ret;
}
q.reSet();
int size = temp.size();
if( size == 0 )
{
cout<<"stack is empty " <
return -1;
}
else
{
size--;
}
while(size--)
q.enQueue(temp.deQueue());
temp.reSet();
return result;
}
void disp()
{
q.disp() ;
}
};