-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueueUsingLL.c
61 lines (49 loc) · 1.24 KB
/
QueueUsingLL.c
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
queue * enq(queue *q,int val){
struct node* new = create(val);
if(q->rear == NULL){
q->rear = q->front = new;
}
else{
q->rear->next = new;
q->rear = new;
}
return q;
}
struct node* deq(queue *q){
if(q->front==NULL) return NULL;
struct node* temp = q->front;
q->front = q->front->next;
if(q->front == NULL) q->rear =NULL;
return temp;
}
void disp(queue* q){
struct node* temp = q->front;
while(temp!=NULL){
printf("%d ",temp->data);
temp=temp->next;
}
}
int main(){
queue *q =(queue *)malloc(sizeof(queue));
q->front =NULL;
q->rear =NULL;
while(1){
int c=1,x;
struct node* n = NULL;
printf("Choice:: ");
scanf("%d",&c);
switch(c){
case 1: scanf("%d",&x);
enq(q,x);
disp(q);
break;
case 2: n=deq(q);
printf("%d got deleted!\n",n->data);
break;
case 3: disp(q);
break;
default: printf("Invalid Choice\n\n");
break;
}
}
}