-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue_list.c
74 lines (57 loc) · 1.02 KB
/
queue_list.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
68
69
70
71
72
73
74
//queue_list.c
#include <stdio.h>
#include <stdlib.h>
typedef
struct list
{ int data;
struct list *next;
} node;
node *front=NULL,*rear=NULL;
node* newNode(int element)
{
node *temp=(node*)malloc(sizeof(node));
temp->data=element;
temp->next=NULL;
return temp;
}
int isEmpty()
{ if(front==NULL)
return 1;
else
return 0;
}
int atFront()
{ return front->data;
}
void insert(int element)
{
node *temp=newNode(element);
if(isEmpty())
front=rear=temp;
else
{ rear->next=temp;
rear=temp;
}
}
void del()
{ node *temp=front;
if(isEmpty())
printf("Queue empty\n");
else
{
front=front->next;
if(front==NULL) rear=NULL;
free(temp);
}
}
main()
{
insert(10); insert(11); insert(12); insert(13); insert(14);
if(!isEmpty())
printf("At front we have %d\n",atFront());
del(); del(); del();
if(!isEmpty())
printf("At front we have %d\n",atFront());
del(); del();
del(); // should get queue empty message
}