File tree 1 file changed +100
-0
lines changed
1 file changed +100
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include<stdio.h>
2
+ #include<stdlib.h>
3
+ #define maxsize 5
4
+ int front = -1, rear = -1;
5
+ int queue[maxsize];
6
+
7
+ void insert()
8
+ {
9
+ int item;
10
+ printf("\nEnter the element\n");
11
+ scanf("\n%d",&item);
12
+ if(rear == maxsize-1)
13
+ {
14
+ printf("\nOVERFLOW\n");
15
+ return;
16
+ }
17
+ if(front == -1 && rear == -1)
18
+ {
19
+ front = 0;
20
+ rear = 0;
21
+ }
22
+ else
23
+ {
24
+ rear = rear+1;
25
+ }
26
+ queue[rear] = item;
27
+ printf("\nValue inserted ");
28
+
29
+ }
30
+ void delete()
31
+ {
32
+ int item;
33
+ if (front == -1 || front > rear)
34
+ {
35
+ printf("\nUNDERFLOW\n");
36
+ return;
37
+
38
+ }
39
+ else
40
+ {
41
+ item = queue[front];
42
+ if(front == rear)
43
+ {
44
+ front = -1;
45
+ rear = -1 ;
46
+ }
47
+ else
48
+ {
49
+ front = front + 1;
50
+ }
51
+ printf("\nvalue deleted ");
52
+ }
53
+
54
+
55
+ }
56
+
57
+ void display()
58
+ {
59
+ int i;
60
+ if(rear == -1)
61
+ {
62
+ printf("\nEmpty queue\n");
63
+ }
64
+ else
65
+ { printf("\nprinting values .....\n");
66
+ for(i=front;i<=rear;i++)
67
+ {
68
+ printf("\n%d\n",queue[i]);
69
+ }
70
+ }
71
+ }
72
+ void main ()
73
+ {
74
+ int choice;
75
+ while(choice != 4)
76
+ {
77
+ printf("\n*************************Main Menu*****************************\n");
78
+ printf("\n=================================================================\n");
79
+ printf("\n1.insert an element\n2.Delete an element\n3.Display the queue\n4.Exit\n");
80
+ printf("\nEnter your choice ?");
81
+ scanf("%d",&choice);
82
+ switch(choice)
83
+ {
84
+ case 1:
85
+ insert();
86
+ break;
87
+ case 2:
88
+ delete();
89
+ break;
90
+ case 3:
91
+ display();
92
+ break;
93
+ case 4:
94
+ exit(0);
95
+ break;
96
+ default:
97
+ printf("\nEnter valid choice??\n");
98
+ }
99
+ }
100
+ }
You can’t perform that action at this time.
0 commit comments