Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- //Queue with List
- struct node
- {
- int data;
- struct node *link;
- };
- struct node *front=NULL;
- struct node *rear=NULL;
- void enqueue(int x)
- {
- struct node *N = new node;
- N->data=x;
- N->link=NULL;
- if(rear==NULL)
- {
- rear=N;
- front=N;
- }
- else
- {
- rear->link=N;
- rear=rear->link;
- rear->link=front;
- }
- }
- void dequeue()
- {
- if(front==NULL)
- {
- cout<<"No values in queue"<<endl;
- }
- else
- {
- if (front==rear)
- {
- front=NULL;
- rear=NULL;
- }
- else
- {
- front=front->link;
- }
- }
- }
- void display()
- {
- struct node *t =front;
- while(t!=rear)
- {
- cout<<t->data<<"->";
- t=t->link;
- }
- cout<<t->data<<endl;
- }
- int main()
- {
- enqueue(10);
- enqueue(20);
- enqueue(30);
- enqueue(40);
- display();
- dequeue();
- display();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement