0% found this document useful (0 votes)
10 views2 pages

QUEUE

Uploaded by

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

QUEUE

Uploaded by

f2023408080
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include<iostream>

using namespace std;


class node{
public:
int data;
node *next;
node()
{
data=0;
next=NULL;
}
};
class queue{
node *head;
int top, cap;
public:
queue(int c):head(NULL),top(0),cap(c){
}
int isfull()
{
if(top==cap)
{
cout<<"Queue overloaded"<<endl;
return 1;
}
return 0;
}
int isempty()
{
if(top==0)
{
cout<<"Queue is empty"<<endl;
return 1;
}
return 0;
}
void push(int d)
{
if(!isfull())
{
node *x=new node;
x->data=d;
if(head==NULL)
{
head=x;

}
else
{
//cout<<"OK";
node *move=head;
while(move->next)
{
move=move->next;
}
move->next=x;
//cout<<x->data;
}
top++;
}
}
void pop()
{
if(!isempty())
{
node *temp=head;
head=head->next;
delete temp;
temp=NULL;
top--;
}
}
void display()
{
if(!isempty())
{
node *move=head;
while(move)
{
cout<<move->data<<"\t";
move=move->next;
}
cout<<endl;
}
}
};
int main()
{
queue q(5);
q.push(10);
q.push(20);
q.pop();
q.pop();
//q.pop();
q.push(12);
q.push(11);
q.push(32);
q.push(2);
q.push(9);
q.display();
}

You might also like