-
Notifications
You must be signed in to change notification settings - Fork 0
/
queuelinklist.cpp
65 lines (52 loc) · 895 Bytes
/
queuelinklist.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
#include<iostream>
using namespace std;
struct Node{
int data;
Node* next;
};
Node *fron=NULL;
Node *rear=NULL;
struct Queue{
Node *fron;
Node *rear;
Queue(){
fron=rear=NULL;
}
void enq(int v){
Node *ptr= new Node();
ptr->data=v;
ptr->next=NULL;
if(fron==NULL){
fron=ptr;
rear=ptr;
}
else{
rear->next=ptr;
rear=ptr;
}
}
void deq(){
if(fron==NULL){
return;
}
Node *ptr = fron;
fron=fron->next;
if(fron==NULL){
rear=NULL;
}
delete (ptr);
}
};
int main(){
Queue q;
q.enq(4);
q.enq(6);
q.enq(12);
q.enq(23);
q.enq(8);
q.enq(90);
q.deq();
cout<<(q.fron)->data<<endl;
cout<<(q.rear)->data<<endl;
return 0;
}