forked from akshitagupta15june/100code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcircular_queue_using_linklist.c
More file actions
114 lines (109 loc) · 2.05 KB
/
Copy pathcircular_queue_using_linklist.c
File metadata and controls
114 lines (109 loc) · 2.05 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
};
struct node *front=NULL;
struct node *rear=NULL;
struct node *enqueue(int data);
struct node *dequeue();
struct node *peak();
struct node *display();
struct node *enqueue(int data)
{
struct node *newnode;
newnode=(struct node*)malloc(sizeof(struct node));
newnode->data=data;
newnode->next=NULL;
if(front==NULL && rear==NULL)
{
front=newnode;
rear=newnode;
}
else
{
rear->next=newnode;
rear=newnode;
}
}
struct node *dequeue()
{
struct node *temp;
temp=front;
if(front==NULL && rear==NULL)
{
printf("\n QUEUE UNDERFLOW\n");
}
else if(front==rear)
{
printf("Item deleted %d ",front->data);
front=NULL;
rear=NULL;
}
else
{
printf("\n The item which is deleted is %d ",temp->data);
front=front->next;
free(temp);
}
}
struct node *peak()
{
if(front==NULL && rear==NULL)
{
printf("\n QUEUE Empty");
}
else
{
printf(" %d",front->data);
}
}
struct node *display()
{
struct node *temp;
temp=front;
if(front==NULL && rear==NULL)
{
printf("\n QUEUE Empty");
}
while(temp!=NULL)
{
printf("\n%d ",temp->data);
temp=temp->next;
}
}
int main()
{
int ch,data;
system("clear");
do
{
printf("\nEnter following keys\n1:ENQUEUE\n2:DEQUEUE\n3:PEAK\n4:display\n5:(0) to exit\t");
scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\nEnter data\t");
scanf("%d ",&data);
enqueue(data);
break;
case 2:
dequeue();
break;
case 3:
peak();
break;
case 4:
display();
break;
default:
printf("wrong choice");
}
}
while(ch!=0);
ch=getchar();
return 0;
}