-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.c
95 lines (93 loc) · 2.53 KB
/
test.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
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
#include <stdio.h>
void main()
{
int item, priority, n, option, Q[10], P[10], i;
int front = -1, rear = -1;
printf("Enter the size of queue");
scanf("%d", &n);
do
{
printf("1.Enqueue \n 2.Dequeue \n 3.Display \n 4. quit");
printf("\nEnter the option: ");
scanf("%d", &option);
switch (option)
{
case 1:
printf("\nEnter the element to be inserted : ");
scanf("%d", &item);
printf("Enter the priority: ");
scanf("%d", &priority);
if (front == 0 && rear == n - 1)
{
printf("Queue is full");
}
else if (front == -1 && rear == -1)
{
front = 0;
rear = 0;
Q[rear] = item;
P[rear] = priority;
}
else if (rear == n - 1){
for (i = front; i <= rear; i++)
{
Q[i-front] = Q[i];
P[i - front] = P[i];
}
rear= rear-front;
front = 0;
for (i = rear; i > front; i--)
{
if (P[i] < priority)
{
Q[i+1] = Q[i];
P[i+1] = P[i];
}
}
}else{
Q[i+1] = item;
P[i+1] = priority;
rear++;
}
break;
case 2:
if (front == -1)
{
printf("Queue is empty");
}
else if (front == rear)
{
printf("\nDeleted item : %d", Q[front]);
front = rear = -1;
}
else
{
printf("\nDeleted item : %d", Q[front]);
front = front + 1;
}
break;
case 3:
if (front == -1)
{
printf("Queue is empty");
}
else
{
for (i = front; i <= rear; i++)
{
printf("%d\t", Q[i]);
}
printf("\n");
for (i = front; i <= rear; i++)
{
printf("%d\t", P[i]);
}
}
break;
case 4:
break;
default:
printf("invalid entry");
}
} while (option != 4);
}