File tree 1 file changed +84
-0
lines changed
1 file changed +84
-0
lines changed Original file line number Diff line number Diff line change
1
+ // QUEUE OPERATION IN C
2
+ #include <stdio.h>
3
+ # define SIZE 100
4
+ void enqueue ();
5
+ void dequeue ();
6
+ void show ();
7
+ int inp_arr [SIZE ];
8
+ int Rear = - 1 ;
9
+ int Front = - 1 ;
10
+ main ()
11
+ {
12
+ int ch ;
13
+ while (1 )
14
+ {
15
+ printf ("1.Enqueue Operation\n" );
16
+ printf ("2.Dequeue Operation\n" );
17
+ printf ("3.Display the Queue\n" );
18
+ printf ("4.Exit\n" );
19
+ printf ("Enter your choice of operations : " );
20
+ scanf ("%d" , & ch );
21
+ switch (ch )
22
+ {
23
+ case 1 :
24
+ enqueue ();
25
+ break ;
26
+ case 2 :
27
+ dequeue ();
28
+ break ;
29
+ case 3 :
30
+ show ();
31
+ break ;
32
+ case 4 :
33
+ exit (0 );
34
+ default :
35
+ printf ("Incorrect choice \n" );
36
+ }
37
+ }
38
+ }
39
+
40
+ void enqueue ()
41
+ {
42
+ int insert_item ;
43
+ if (Rear == SIZE - 1 )
44
+ printf ("Overflow \n" );
45
+ else
46
+ {
47
+ if (Front == - 1 )
48
+
49
+ Front = 0 ;
50
+ printf ("Element to be inserted in the Queue\n : " );
51
+ scanf ("%d" , & insert_item );
52
+ Rear = Rear + 1 ;
53
+ inp_arr [Rear ] = insert_item ;
54
+ }
55
+ }
56
+
57
+ void dequeue ()
58
+ {
59
+ if (Front == - 1 || Front > Rear )
60
+ {
61
+ printf ("Underflow \n" );
62
+ return ;
63
+ }
64
+ else
65
+ {
66
+ printf ("Element deleted from the Queue: %d\n" , inp_arr [Front ]);
67
+ Front = Front + 1 ;
68
+ }
69
+ }
70
+
71
+ void show ()
72
+ {
73
+ int i ;
74
+
75
+ if (Front == - 1 )
76
+ printf ("Empty Queue \n" );
77
+ else
78
+ {
79
+ printf ("Queue: \n" );
80
+ for (i = Front ; i <= Rear ; i ++ )
81
+ printf ("%d " , inp_arr [i ]);
82
+ printf ("\n" );
83
+ }
84
+ }
You canβt perform that action at this time.
0 commit comments