-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathqueue_ll.c
67 lines (61 loc) · 957 Bytes
/
queue_ll.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
62
63
64
65
66
67
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
}*front;
void enqueue(int n)
{
printf("-> %d enqueued! \n",n);
if(front==0)
{
front=(struct node*)malloc(sizeof(struct node));
front->data=n;
front->next=NULL;
}
else
{
struct node *nw=(struct node*)malloc(sizeof(struct node));
nw->data=n;
struct node *temp=front;
while(temp->next!=NULL)
{
temp=temp->next;
}
temp->next=nw;
}
}
void read()
{
struct node *temp=front;
printf("Read Queue Content: \n");
while(temp)
{
printf("%d \n",temp->data);
temp=temp->next;
}
}
int dequeue()
{
struct node *temp=front;
front=front->next;
printf("-> %d dequeued!\n",temp->data);
return temp->data;
}
int isEmpty()
{
if(front==0)return 1;
else return 0;
}
int main()
{
enqueue(10);
if(!isEmpty())enqueue(20);
if(!isEmpty())enqueue(30);
if(!isEmpty())enqueue(40);
if(!isEmpty())enqueue(50);
read();
dequeue();
read();
}