-
Notifications
You must be signed in to change notification settings - Fork 1
/
14_queue_linkedlist.c
63 lines (58 loc) · 1010 Bytes
/
14_queue_linkedlist.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
#include<stdio.h>
#include<stdlib.h>
struct node
{
int num;
struct node *next;
}*rear,*front;
void insert(int num)
{
if(front==NULL)
{
front=(struct node*)malloc(sizeof(struct node));
front->num=num;
front->next=NULL;
rear=front;
}
else
{
struct node *new=(struct node*)malloc(sizeof(struct node));
new->num=num;
new->next=NULL;
rear->next=new;
rear=new;
}
}
void delete()
{
if(front==NULL)
printf("\nQueue underflow!!!\n");
else
front=front->next;
}
int main()
{
int i,n,a;
do
{
printf(" Enter Option\n\t1. Enqueue\n\t2. Front\n\t3. Dequeue\n\t4. Exit \n ");
scanf("%d",&n);
if(n==1)
{
printf("\nEnter number ");
scanf("%d",&a);
insert(a);
}
else if(n==2)
{
if(front!=NULL)
printf(" Front element : %d \n ",front->num);
else printf(" Empty Queue!\n");
}
else if(n==3)
delete();
else if(n==4)
break;
}while(n!=4);
return 0;
}