0% found this document useful (0 votes)
42 views20 pages

DS - Practical - 5

The document discusses a circular queue implementation in C code. It defines macros and variables for the queue including a front and rear index. Functions are defined for enqueue, dequeue and display the queue. The main function implements a menu driven program to test the queue operations by inserting, removing and displaying elements.

Uploaded by

Soha KULKARNI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views20 pages

DS - Practical - 5

The document discusses a circular queue implementation in C code. It defines macros and variables for the queue including a front and rear index. Functions are defined for enqueue, dequeue and display the queue. The main function implements a menu driven program to test the queue operations by inserting, removing and displaying elements.

Uploaded by

Soha KULKARNI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

PRACT\CAL \\_\C) : S 2o lfo Lf f

C\:nw \an ~ VJilU:.. av e,:n cDV'Yle-$ the f~.Dlef.CL


.J-J
.r.Ji._ a_.___ _-,;
>-.-:Z.x.;P
.../
space 1Y) \ivw o:n ope11e irot'\emov:J·,:)d ~s.
, - - - - + - - - ----1.ll_-C...l...}ll..
L..:U.J~_Q.jw..QJ.t..e.._.e.wn.e,it'.U:!>_ .CJJl0.- pr'1j SI (I) [( ~ ~- dl :£ .d ..----i

..____ __ __u_ Tn',hc,\\~e po.nt ;: - \ t ..:n m= 0 '-\.¥\cl y"Y\¼X5.i 3e.. = ta_


'.l. ::: ::. __(.~e.coi +: lJ /_ Mflx~L3e.
J
1 -- -- -- -- -------t-"'~~_f.v 10 u e () ,.r nflai..i2 mo $Sc.. e..
.wx: L_JZ e.h.J..n.n •
5
2,o 4-0 Lf j

r--------!+ ---">U'-~W L~e. ) lJ s~cb.t - :: \


r------- -----sd : f-" 0 ~t :. .:ne. u,.')"\ 0

~ E>_Q.;D :;. c..~e.W\.. -rt) 1/. MA-)($ l L-L


r------ W N ,,, ,) io~e.:n-\- tk e ele.ro.e.frl. cd:- ~~ G-uz.dU

Deov11 e,1 e

1--------- ~~_.fuu. ..L..1.,,s .,J.._~nc :. cJ we ho...v'e. ~~n c..·\.~LU ..\.~eJ~__.


1------.-~~~~----+-..........,-~ b of e =net. -b ·o D OJ\ d Q..... f:rtC 3.:no.n:t ~
C: \Use.rs\Linza\Source\Repos\circularqueueimplementation.c 1
1 t _nc ude<stdio . h>
2 d i 11AX_LNC 10
3 int cirq_lnc[MAX_LNC];
4 int front_lnc = -1;
5 int rear_lnc = -1;
6
7 void enqueue_lnc(int item_lnc)
8 {
9 if ((front_lnc = 8 && rear_lnc -- 11AX_LNC - 1) I I (front_lnc -
rear_lnc + 1))
18 {
11 printf( "\nQUEUE OVERFLOW\n" );
12 return ;
13 }
14 if (front_lnc = - 1)
15 {
16 front_lnc = 8;
17 rear_lnc = 8 ;
18 }
19 else
20 {
21 if (rear_lnc = HAX_LNC - 1)
22 {
23 rear_lnc = 8;
24
25 }
26 else
27 {
28 rear_lnc += l;
29 }
38 }
31 cirq_lnc[rear_lnc] = 1tem_lnc;
32 }
33
34 void dequeue_lnc()
35 {
36 if (front_lnc = -1)
37 {
38 printf( "\nQUEUE UNDERFLOW\n" );
39 return ;
40 }
41 printf( "\nElement deleted from the queue is %d\n" , cirq_lnc
[ front_ lnc]) ;
42 if (front_lnc =
rear_lnc)
43 {
44 front_tnc = - 1 ;
45 rear_tnc = - 1;
46 }
1.n else
C:\Users\L inza\Sourc e\Repos\c ircularque uei mplementation . c 2
u {
U9 if (front_lnc == MAX_LNC - 1)
50 {
51 front_tnc =8 ;
52 }
53 else
SU {
55 front_tnc += l;
56 }
57 }
58 }
59 void disptay_tn cO
60 {
61 int frontpos_t nc = front_tnc , rearpos_tn c = rear_tnc;
62 if (front_lnc == - 1)
63 {
6U printf( "\nQUEUE IS EMPTY\n" );
65 return ;
66 }
67 printf( "\nQueue Elements : \n" ) ;
68 if (frontpos_tnc <= rearpos_tn c)
69 {
78 while (frontpos_tnc <= rearpos_tn c)
71 {
72 printf( " \d" , cirq_tnc(f rontpos_tn c]);
73 frontpos_tnc++;
7U }
75
76 }
77 else
78 {
79 while (frontpos_tnc <= HAX_LNC - 1)
80 {
81 printf( " \d" , cirq_tnc(f rontpos_tn c));
82 frontpos_tnc++ ;
83 }
SU frontpos_t nc = 0;
85 white (frontpos_tnc <= rearpos_tn c)
86 {
87 printf( " \d" , cirq_tnc(f rontpos_tn c]) ;
88 frontpos_t nc++;
89 }
90 }
91 printf( "\n" ) ;
9 }
9 int main()
9 {
9c int choice_lnc , item_tnc ;
96 do
C: \Users\Linza\Source\Repos\circularqueueimplementation . c 3
97 {
98 printf( "l . Insert element to queue\n" );
99 printf( "2 .Delete element from queue\n" );
180 printf( "3 .Display all elements of queue\n" ) ;
181 printf( "4.Quit\n" );
182 printf( "Enter your cho1ce : ") ;
183 scanf("\d" , &choice_lnc) ;
181J switch (choice_lnc)
185 {
186 case 1 :
187 printf( "Input the element you want to insert :\n" );
188 scanf( "%d" , &item_lnc);
189 enqueue_lnc(item_lnc) ;
118 break ;
111 case 2 :
112 dequeue_lnc() ;
113 break ;
114 case 3:
115 display_lnc();
116 break ;
117 case 4 :
118 break ;
119 default :
128 printf( "\nWrong Choice . Please select a valid option . \n ");
121
122 }
123 } while (choice_lnc != 4);
12 return e;
125 }
126
127
ii Devdoptt Cornm,nd Prompt fo, VS 2022 X
ii Detdoptt Comnw,d Prompt fo, VS 20l.2 X
ii Derdoptt Comm,nd Prompt fo, VS 2022 X
ii De.-doptt Cornnw,d Prompt fo, VS 2022 X
ii Detdop" Comnvnd Prompt fo, VS 2ll!2 X
ii De.-.ioptt Comnvnd Prompt fo, VS 2022 X
ii Derdoptt Cornnw,d Prompt fa< VS 2022 X
~CJtted
0

0 -- - -

-F-
r. (.(
l'.)rv 1R \1.t.L
i 0 -
11) ~-~~--
_&i 2,;E:3)Ji _c Q ::: ;: ?,)
C (':, - -
'J c_ 0 :=.-:. - \J _..f~- - - - - - - - - -

--------
-P■a_•N_o
.. ---'Y.O~
D111: ,

_ _..--, --e.h~e_ CJ)


if C..(Q -- Q Yrb ~ 'tJ l \ Co G J}- F
~~\· _r (Q ::: IJ V
e\ ~ e.,__
--+---~4 Cs =~~1 -
e\s_e._ _
~

---+---~= ~ - -
- - - r - ( . _ c : v101 JO ~ [ c., J - 7

~ I

==7)

-F

7
l 2. 3 y 5 G:, 7 'b

0 I ..?3 L,\SG,, i
\ l ~ 4'!>Co1
D111:

\
~uo(lO~ •\ ( o0 ~~- ~ - - -
.---------L- if a:.o C irJt ~ r.;:tJ~
\ &, Co ~ : - \~ ='..J::...-----,_J.J----------
~---~~\£"e.__- - -
£-__ (_'6
~ ~ - 1 . . - ~':...J-
' =-;:. 9J - E- - - - - - - - -
e\ ~e ~
,hq ,.~ =. 9
1 2. 3 u 5 G, ,

-T

-T

-\
1-- ---. ...L J_
, e. UL<..=- °tj :y
--- -~ 1. nt ~
--- --~ P-Q ~-: .. 5
--~ \e. _( 5! ( ::-9 ) -1
p---:n\n'l ~ -~ -- l ' l 'l.\ ';\ L.\ \ $ l c; \
___f$cwc~~-=- ~
,__ _wb, l ~ e_C. '2~ =- qJ -T

i- -- ~: \ '(\LJ~ ~ ~ -LLI 21~ \1...t \s \eo \-, \


j__ -~- .>,U J.J, -~ ::: ],.__

~-~ .._._ ._._ .._._ __-- C7 <- ~ q':) -T~_ ---- -.-= ~= :::: :::: ;=~ ~= :;:; ---- -I
--r-

\ 2.. 3 L\5 Co 7 '3

-T

23y5~7S9\D

-----
::. 2
----------J

:. 2. 3 S <a 7'aC\ \0

-T -T

3 G 7 \D

_T

-T
~-_J_
(JI J
LC 2 = =C ~~ S- =ct J \\ C2 - \ o) J
::.:.:. 1) -F-

C\~C \j - -
--~C-1 .--_Q_ -
~,._,_,.,_---W-lhL a:J =- LL _ _ __

-f-

LJJLl"'IC W;:: \\ \2 3 y S Co 7 <zs °\ lD

-F-
-F
------
J-1

-f

You might also like