-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue.cpp
48 lines (47 loc) · 859 Bytes
/
queue.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
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<iostream>
struct Node{
int data; Node* link;
};
void disp(Node* front){
while (front != NULL){
printf("\n%d", front->data);
front = front->link;
}
}
void enq(Node** front,Node** rear, int val){
Node* temp = (Node*)malloc(sizeof(Node));
if (*front == NULL&&*rear == NULL){
temp->data = val;
temp->link = NULL;
*front = *rear = temp;
(*front)->link = *rear;
}
else{
temp->data = val;
temp->link = NULL;
(*rear)->link = temp;
*rear = temp;
}
}
void deque(Node** front){
Node* temp = (*front)->link;
free(*front);
*front = temp;
}
int main(){
Node* front=NULL,*rear = NULL;
enq(&front, &rear, 1);
enq(&front, &rear, 3);
enq(&front, &rear, 6);
enq(&front, &rear, 4);
disp(front);
puts("");
deque(&front);
deque(&front);
disp(front);
getchar();
return 0;
}