0% found this document useful (0 votes)
10 views

dsa

Uploaded by

sonukumar05160
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

dsa

Uploaded by

sonukumar05160
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Stack Uauy 0May

noludk rStdo. h>

Votd puet(;
Ved pep();
ed peek (),"

eit stack l50Jiu plen -O, n, top : 1,


Vod maunt)

puntyC" Frtes he numbee e emenh u he shade")


Scanj e/d", & n);
buk (" SToch nmplevneud.atwn wsng amay \r'
wuie pliou =4)
puuikh(" ehoose pne ponm he 6elow oplvey. \u
. .

Frit ")
puntfCd. Paush ln2. Pop \n 3. Peek \n4.
\n);
punty u\n Enter you epuen
Scan (v/d", &opUn)
Lwtah ( eplkon)

Cae 1:

PLuoh ()
beeak

Cane 2
Pop),
beak

Cane 3
pee k)
buak
Catse 4

Puutf C Pnitiny ")


beeck

default
3
(" PLeast Fnlet Valud opluen),
Punt

void push C)
u valu
top= -n)
punt Cln Owhiow")

Pauntf ( Fnlb h
value ?),
Scante/od",3 val)
to tep t1
Stack tfop] valie,

Vord bepl)

IE ( top = -

1)
Puintf C Undeflo ");

te top -1
void beek ()

for ( i bp, i>=O; i--)


( d d \ n " , stach Ci]);
puntt

if cto :
-1)

puntf (" Skack ernpty ")

utpat
Lunta Sear c

# incliude TStdo. h>

nt Aamch ( u t aiiayl , n t n unt x)

for ( unl i: O) ikni i+t)

4laeray lij =x) -

Ackuun ii

Lut man ( )

ut ainal]= i2,4,6,0,1,9?,
wtx 1 ; |
ut n izeef (arnay ) /sizeoh ( a2nay lö);
mt msult &earh (May n1X)i
not føud")
(Aesult = =
-4) 7 puntf(" E lmentF
eund a Lnoln /d", suult)
CPleneut
Pain

Ouwput
Bunany seauch esatuue
mclude rctdio.h
t buary Search (2ut ut L
low
avay [1, Lnt x,
uut igth)

uelule (tew k =higtu)


uit midLow (high Low)2
(atkay Tmid} = X

mid
(ara lmwd) 4x)
Lew = sd+11
hugm mud -L,

Aetun 1

mam (void)

wt May [] {3, -
4,S, 6,7, 8, 9f}
ud n:
size (anay) / size (auag lo1),
wd X 4j
bunary Seatch ( aay, X, 0, n
-

1);
4 (esuult 1)
puntt (" Wot found"),

Puuntr Flement i f o u d tsund af nden/o

Aeaull)
AAtin 0,
Bnary seasch Rensue

#aicluclc TMdio, h>


nbinacy seaich ( ut atta l), mt v, n t louo,
int high)

high > lerw)


ut mid lew +
( huigh -

low)/2,
(tray Cmid) ))
e n mmd

(anay lmud ] >x)


Ktkuut bunays earcl (axnoy 1 X Low, nnud - D ;

elun buay Stauch ( asmay, x, nud+ 1, higk)


Aehuun-1,

ud man (void)

ud aay J 3,4,S,6,7, 8, 91,


nk n izen isay) / uizeof C anay lõ),

ult benay Seaneh ( aray, x, C,n -1),


4 n u l t : -1))
punkf (" net tound");

Pnt (" Elennent found atunden Jd" keault),


Bloclk uung Laked

h > o.
include rstdi
i n c i u d i ( SHdlib.h>

Stuct Node 1
ut dala
sAkect Node *nent,

F
Node top NULL
vofcd puslh (ud value)

*newNode (stauch Node))i


stauuc Nocde malloe (Mze e
wNoce = (teuc Node *)
ne
= Value
> dal
ne Node
-

NVLU)
Chop =
=

nent- NULLi
nen Node ->
?

newNod - nent = top

tep heuw Node Jnsnked \n \n),


(Node
puntf
F
uk bep C)1
tofptop = NULL)
Siack Undesjlnlu");
Punt f(" \n

shuct Nod *tthp top


tnp-d ata tpp -> data i
nt
nt
Lolptp-?nmk
fAee (temp)
KAluru tentp dala,
F
vold daplay ti

6 op - NULU

Pavrk f n Stoacle lnderptow n "


tl

PRnlt Che stacke w ln")


3tuuct Node * tentp tep
-> nent | = NULL)
ushule (tewtp

Put (7*d....> ", turp-7dlata ),


tenp= tenp -? nenti
NULL {n \n", tennp-> dala),
pnntf ( / d . . -

ink maun ()

uit clneCe, valuu


\n snptement q stach uug lurteol ist\n
put (
while (i)
1n3. dia4tay n 4 Fxt \n"),
Putf (u), fusbn ). Pop
puntf ( \n tnter youu cheice ")
Soan (/»d "', & cheice))

Cae I
Punitf C"\ fnter Hhe valt s
wnsect "),'
Scan C+d", B value),
Puah value)
bteah
Cane 2
Pntt Pophed elcmeut n'f-d \n"Pop ()):
bteaki
Cane 3
display (),
beak
Cae 4
eit Co);

defuult
Paint f C\h Wou cheuce \n")

You might also like