forked from AugustineAykara/Data-Structure-In-C
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue-linkedList.c
More file actions
99 lines (85 loc) · 1.29 KB
/
queue-linkedList.c
File metadata and controls
99 lines (85 loc) · 1.29 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
#include<stdio.h>
#include<stdlib.h>
struct node {
int data;
struct node *addr;
}*rear = NULL, *front = NULL;
void insertQueue()
{
int item;
struct node *n;
n =(struct node *) malloc (sizeof(struct node));
printf("\n Enter the item to be inserted : ");
scanf("%d", &item);
n -> data = item;
n -> addr =NULL;
if (front == NULL)
{
rear = front = n;
}
else
{
rear -> addr = n;
rear = n;
}
}
void deleteQueue()
{
if (front == NULL)
{
printf("\n QUEUE UNDERFLOW !!!");
}
else
{
printf("\n Element %d has been deleted from the queue ", front -> data);
front = front -> addr;
}
}
void display()
{
struct node *temp;
ptr = front;
if (ptr == NULL)
{
printf("\n LIST IS EMPTY NOW!!!");
}
else
{
printf("\n");
while(ptr != NULL)
{
printf(" %d <-", temp -> data);
ptr = ptr -> addr;
}
}
printf("\n");
}
void main()
{
int ch;
while(1)
{
printf("\n 1. INSERT to Queue \n 2. DELETE from Queue \n 3. DISPLAY \n 4. EXIT ");
printf("\n Enter your choice : ");
scanf("%d", &ch);
switch(ch)
{
case 1:
insertQueue();
display();
break;
case 2:
deleteQueue();
display();
break;
case 3:
display();
break;
case 4:
exit(0);
break;
default:
printf("\n !!! INVALID CHOICE !!!");
}
}
}