-
Notifications
You must be signed in to change notification settings - Fork 0
/
Implementation of Queue using LL.cpp
86 lines (76 loc) · 1.28 KB
/
Implementation of Queue using LL.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <iostream>
using namespace std;
typedef struct node{
int data;
node* next;
};
node *Front=NULL;
node *rear=NULL;
void Enqueue(int n)
{
node *temp=new node();
temp->data=n;
temp->next=NULL;
if(Front==NULL&&rear==NULL)
{
Front=rear=temp;
return;
}
rear->next=temp;
rear=temp;
}
void Dequeue()
{
node *temp;
temp=Front;
if(Front==NULL)
{
cout<<"Queue is empty"<<endl;
}
else if(Front==rear)
{
Front=rear=NULL;
}
else
{
Front=Front->next;
}
free(temp);
}
int FRONT()
{
if(Front==NULL)
cout<<"Queue is empty"<<endl;
else
{
return rear->data;
}
}
void display()
{
node *temp;
temp=Front;
while(temp!=NULL)
{
cout<<temp->data<<" ";
temp=temp->next;
}
cout<<endl;
}
int main()
{
Enqueue(47);display();
Enqueue(6);display();
Enqueue(4);display();
Enqueue(5);display();
Enqueue(2);display();
Enqueue(3);display();
Enqueue(8);display();
Dequeue();display();
Dequeue();display();
Dequeue();display();
Enqueue(10);display();
Enqueue(12);display();
cout<<FRONT();
return 0;
}