Queue


Program

#include<iostream>
using namespace std;
struct node{
int data;
node *next;
};
class ListQueue{
node *head,*tail;
public:
ListQueue()
{
head=NULL;
tail=NULL;
}
void EnQueue(int info)
{
node *NewNode=new node;
    NewNode->data=info;
    NewNode->next=NULL;
    if(head==NULL)
    {
    head=NewNode;
}
else
{
tail->next=NewNode;
}
tail=NewNode;
}
int DeQueue(){
if(IsEmpty())
{
cout<<"Underflow occurs ";
return 0;
}
int info;
node *cur=head;
info=head->data;
head=head->next;
delete cur;
            return info;
}
int IsEmpty()
{
if(head==NULL)
return 1;
return 0;
}
};
int main()
{
ListQueue Q;
Q.EnQueue(20);
cout<<Q.DeQueue();
}

Comments

Post a Comment

Popular posts from this blog

Stack

Operation on Single Linked List

EXTRA INFORMATION ABOUT TECHNOLOGY