-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueuUsingLinkLIst
78 lines (68 loc) · 1.38 KB
/
QueuUsingLinkLIst
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
/*This Flie is Made by VISHESH YADAV (ECE-1) Netaji Subhas University Of technology*/
#include <stdio.h>
#include <stdlib.h>
typedef struct node{
int data;
struct node* next;
}node;
node*rear=NULL;
node * front =NULL;
node*temp=NULL;
void enqueu (int val){
temp = (node*)malloc(sizeof(node));
temp->data = val;
temp->next=NULL;
if(front==NULL && rear==NULL){
front =rear=temp;
return;
}
rear->next=temp;
rear=temp;
}
void dequeu(){
node*temp =front;
int ans = front->data;
if(front==NULL){
return;
}
if(front==rear){
front=rear=NULL;
}
else{
front=front->next;
}
printf("%d element removed\n",ans);
free(temp);
}
void display(){
node*p=front;
while(p!=rear){
printf("%d->",p->data);
p=p->next;
}
printf("%d",rear->data);
}
int main(){
int val,ch;
while(1){
printf("\n1.Insert\n2.remove\n3.Display\n");
scanf("%d",&ch);
switch(ch){
case 1 : {
printf("Enter element to insert:");
scanf("%d",&val);
enqueu(val);
break;
}
case 2 :{
dequeu();
break;
}
case 3: {
display();
break;
}
default: printf("wrong choice\n");
}
}
}