-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultipleQueue.c
More file actions
85 lines (80 loc) · 1.29 KB
/
MultipleQueue.c
File metadata and controls
85 lines (80 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
#include<stdio.h>
#include<stdlib.h>
typedef struct
{
int key;
}element;
typedef struct node
{
element data;
struct node *link;
}*queuepointer;
queuepointer front[5]={NULL},rear[5]={NULL};
element deleteq(int i)
{
queuepointer temp=front[i];
element item;
if(front[i]==NULL)
printf("queue empty\n");
else
item=temp->data;
front[i]=front[i]->link;
return(item);
}
void addq(element item,int i)
{
queuepointer temp;
temp=(queuepointer)malloc(sizeof(*temp));
temp->data=item;
temp->link=NULL;
if(front[i])
rear[i]->link=temp;
else
front[i]=temp;
rear[i]=temp;
}
void display(int i)
{
queuepointer temp=front[i];
if(!temp)
{
printf("queue empty");
return;
}
for(;temp;temp=temp->link)
printf("%d\n",temp->data.key);
}
int main()
{
int index, choice;
element item;
while(1)
{
printf("Enter 1. Insert 2. Delete 3. Display 4.Exit\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("Enter queue index: ");
scanf("%d",&index);
printf("Enter element to be inserted : ");
scanf("%d",&item.key);
addq(item, index);
break;
case 2:
printf("Enter queue index: ");
scanf("%d",&index);
item=deleteq(index);
if(item.key!=-1)
printf("Element deleted %d", item.key);
break;
case 3:
printf("Enter queue index: ");
scanf("%d",&index);
display(index);
break;
case 4:
exit(0);
}
}
}