-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqueueusingll.c
More file actions
133 lines (118 loc) · 2.39 KB
/
Copy pathqueueusingll.c
File metadata and controls
133 lines (118 loc) · 2.39 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#include<stdio.h>
struct node *temp,*ptr;
struct node *front =NULL;
struct node *rear=NULL;
int e,c=0;
#define Max 10
struct node
{
int data;
struct node *next;
};
struct node *newnode()
{
return(struct node *)malloc(sizeof(struct node));
};
void deletenode(struct node *ptr)
{
ptr->next=NULL;
free(ptr);
}
int main()
{
int ch;
do
{
printf("\n----------Linear Queue operations-----------");
printf("\n 1. INSERT ");
printf("\n 2. DELETE ");
printf("\n 3. PEEK FRONT ");
printf("\n 4. DISPLAY ");
printf("\n 5. EXIT ");
printf("\n---------------------------------------");
printf("\n Enter your choice ");
scanf("%d",&ch);
switch(ch)
{
case 1:
if(c==Max)
{
printf("\n Queue is not Empty!!!");
break;
}
printf("\n Enter the data to be entered : ");
scanf("%d",&e);
insert_q(e);
break;
case 2:
if(front==NULL)
{
printf("\n The Queue is empty!!");
break;
}
printf("\nThe Deleted element from the queue is : %d",delete_q());
break;
case 3:
printf("\n The element in the front is : %d",peek());
break;
case 4:
printf("\n The elements of the Queue are as follows: ");
display();
break;
}
}while(ch!=5);
}
void insert_q(int e)
{
temp=newnode();
temp->data=e;
temp->next=NULL;
if(front==NULL && rear==NULL)
{
front=temp;
rear=temp;
}
else
{
rear->next=temp;
rear=temp;
}
c++;
}
int delete_q()
{
if(front==NULL && rear==NULL)
{
printf("\n theQueue is Empty !!!");
return;
}
e=front->data;
if(front==rear)
{
front=rear=NULL;
}
else
{
front=front->next;
}
return e;
}
void display()
{
if(front ==NULL && rear==NULL)
{
printf("\n The Queue is Empty !!!");
return;
}
ptr=front;
while(ptr!=NULL)
{
printf("\n %d",ptr->data);
ptr=ptr->next;
}
}
int peek()
{
int e=front->data;
return e;
}