0 ratings0% found this document useful (0 votes) 36 views33 pagesDSA Lab Sheet
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
i
ea Shee ob @|
SS x Be
ane Nye
Acre (Sah 5 Singh she 8 NONE
Gan at a ten anit
m 0 wehin Aone
Steph Redlosye Yre As
Step’: - (optic \) WS sakaice We Asay
Skew: Obtei the Element Tadex- y
sitet? Vo idete Ane Teder (oren '
Me Elemet
ADgitthmn: Ac Access “Demand using
ore Qs
ais: Acced&
Example a eee Ye Second Dement 19 $44 e-Dimenst
on |
fay numbenlS1= {10,24 8% 40, Sof |
Joe [433
in SetondElement= Var
ok mow ty cabucnnd:
Expmpie2® po ng ne ement
A ME -Dirrengioned AsHoy
oa mdse ahs
{a2
{B43 5
{5, bs
5
int demenk = =
Conkinue wir she remaining on
oa niche ce Hole — Ximenzior
Aisday Ws Aements,
# incbude )
= bay aM. Tod Made eG . g
, Lob: khee+=2 Linkedk ip,
‘I a oe ee a ames
Sing, Linked Liat x XK
Nede Stauclune:
Sbouct Mode £
int dota;
Stuck Nede* next;
) Creche ist (sitiobize dh empl Dist)
& Pl * Allocate memos ;
Sepa: Geb The nade gach ar One rede usirg alec
SN pa SaaS Nokes dels ve (opal)
to NULL 40 indicate Ve
«ond ef the List.
Steps Set re Yep Painter 04 Yne Dig ko point 4p Shis |
» Ingen of Beginttin. .
Sepl: Allocate memony Yon anew node ,
Siepr2 Set We New Tas Sale to She vi ant bo ingests
ag + Sek Yhe news node a next pointen NS Siege aeete
othe Euswent head Hades!
ShepAt Updake he head pointe eA Yne Wat he point 40 The, ney
ingerrcted node.
© Thsed ok End
eps Bove
e \\ 2
ante SS Wa tied he Roa nade he one ula net
SHePL® Alocake MemMay Bor a new Node
Shepds Set Ane Needs nodes doka to The vadic YEA Larrt to ip, |
SHepAr Se The new Nodes nexd painven vo NUEL- et
Stas TA We Disk 33 empl needis NULL), Sek Rxchead Reinteny,
Ae neem ode
|
\
f
ee Me Fe SNK o{York Ade 0 paint Yo Nye |
Shepbs thes Sones node: ;
ic
ii
Stoo. A
SRPL: Slat aith She heed ek LL
Pe hide 4h ede 13
> kant ‘he Nola, ar por Nede* ett post
paw Jo Mhe next node, by Ain &
S & Witter to Hs neck -poinfer-
Pe List (Deadoceek eA
Steps Soo in 0 oN ved W . nul
Veph- hie Ye Neuman Noe 1% nov 4e
{Sore a tempomary poiften +0 dhe next ne va Hee
» Ges. ee oa he csurem node sf i
Updede The ceed pode paittien to We Begs Ma
sempre pointer (nexinede) to Continve | i
Conte ANAK AreeFin . f
rine Lotth dhe nemo, podem oe
GA White. AC ancien. Mok okes Ye \headk pointer ofa :
ingly ake Var aa inp and ners vA the Distis
A pabindsrome (meods ‘ne gaone, Wwackand ag donwordy
and O othenwige « §
a
Ss
ab include patev = \re>neds
gkrack Hatode * mengedltat = megeTaslish (it,tdp
eosin‘ potintlish (mere List) 4
new O; i
; |
|
er@ Woy
sna
sopeuden B10
Dorl& ac pmo do inpbement a cined® ode Vi
kel tay Be TS pe aor OE
3 a ; vabie.
Indude datas data; (sizeoa( struct Node);
New Node Next = nesNodes
gretunn newNode ;
Void. ingentEnd (Struck Nede*™*head, int doka) f
. Shuck Node* newNode = conecteNode (data) g
iP (1 Fheod f
#\eod = newNodes
F else £
staucr Node* temp heads
nile [Heme =ynexk |= 41 head) emp=tempnrth ie)
temp nexk = NewNode 5 a
NeaNodernext = “heads ;
7 stauct Node* Seancn Node (stoucrNode*heed|
+ 4
stouct Node *emp= heads intveluels
if (MNead) net NULL;
ag
eer Veredo i ,
WP Hemp deka =
Femp —temp ANOAZ
Usnie Lenp! =head)s
} Netw NULL;
= vvabus) anata Fem07
Void print ist (Stowe Node* head) {
Tf (Vhead) netwins
3 5 Stnuct Node *teme zheodd
oO
pari at ("/-d=9 % temp -7daka)s
Yemp = temp 2nects
thide temp ) = head);
Paint ("{heads\r"),
int main £
Stouck Node *head =NULLS
inseskEnd [heady \)5
iNSetEnd (&ead,2)s
Insert End (head, go}s
insestEnd (&head, Ad,
porintlist( head);
Ant SeoadNodue= Sos
gknuck Node* Pound = Gectch Nodel heady search\éllg}
pAaimte(Pound? “founcl AS\in"F “Not fra.” SeoschVakud
gretvor OF :
3bab sheet = 08
XxX anc
fo, __ Set semen BE
“A Trptementation od shack
detine MAX-STZE 100
int StockLmaxisrze};
| Bee
Pemadiong. ae
3 5
Pash(
Ingen an ahemnent)
Bln, Check i the stack 18 YX Hop e=MxSize-4)- |
P22 EF not uur’; ncnement hop by 1+
PS Assign the news element to slack [top].
ae (Remove and sedusin the op adement) i
Steps Check iq Yh i top2= 4).
step: TA ret oy Pera if i Tito 4
Step3> Decrement by 4. ;
aie Relvain “he fae ‘Soue (top element). any
> peek (Rebsn Ahe top ement sith cremaving J
Step: Check 14 Yhe Stack is empty (tap == 2)
© ghep2= TA net empty y mehr the value of Sheree \
3) Ta Empty (check 14 the Black fg empty)
ghep 2° Rekunn top == “13+
cof (Check 4 Whe Stack 12 a)
Qs step: Return Yop == MAX-STZE -L.
|
&SSE
Kea Lise Tmadementaitor od Shack
Node Siouchne +
\. Node , ;
aos ae Node *nek5
stuck Node* top =NULLs |
fostons: : |
ets aot [insert an Yemen’) |
a ode.
acta: sate eer Aes SE OE value yo ont sepa
; , 7 + anil
Prete Re alee pe heey ave
QP (Remave nd ay
reds Check 4 \he ae a Su Ay
StepLe Ty not empty Stone a em ry cael i i"
Shep@: Uplate the ba; prion se paint fo We heel nlelpeatene kee
sets Free the memory of the eld top node aa o “reds
ee.
5 epS Rekunn the data Bloned ta re ‘emperor pointer (top Renal)
C) Peek (Return the Aop adement without sem aiing \
Step check iq “ne stack 13 emp (40 ==NucL).
Steps TA Not empty 7 getunt the deka cd the top node
4) is Emphy (check id The shack ix empty) (top-) deta) |
grep 4% Rerun top ==NULL. |
|
|
|
;
|
eees ee
wantin with the sremalning elem ‘eating
= Waite oc cana check iA an :
Containing, omen TS, ch tits Padanced
# ine ude Ad Yne new dala 40
) deg uewel)
Steph = Check 14 he queue 18 empty (fearon == A).
oT emply 7 print ar emsron MeAroge and mekunn a
dummy Mrobue (4.03, 20 cxpenepaate value
Pep2: La nokVerptys Stone Yretleont clement 3 dao.
gAep3: ey Tncmrement Aront (wrap osound Tq Necemsary)
Bepds Raw Dre Boned deka.
9 igEmeyl
reps Raburn A 1 ont === (empty), othenuataeg
» je rulbel) .
gheplt Revers. 418 ems = MAC STZE An
otherwise a2
Li ;
NKed List Tingdemerctadion of Ouewe
Node Sruclunes
s\auct Node 5
ink dake,
Opencdtons:.
a) engueue (int-daba) .
Siept: Mlocde memory or STE nodes
Sheps Get Ane Ne Ne see eae cnpucseth
hep Ta She queue iz em Jy gorortt ANAM
" : nA eS mom sean XO pon Ao Nhe 189
SiepA+ RO ee Ye next pointer .
Rode Ao point to he NL node. :
GrepSs Updeke rear 10 point 40 the newly ingetted nedef
» Aequerel)
Seek Check fa
the queue ‘3 empty (Pronk ==NuLt). |
alo. of Me Bont Node Win o Femporeny |
Sheps Store a
* Norah Cee), :
rep? Ledate rent +e point 40 ‘he Nee Node in the gueue
NULL oer deg neue ( mecsiing the 7
Steps TA gon \pecomed
ueue be comed empl) sek Mead to NULL 24 wel
GlepSs Free She memeny of She dg ueued i:
Shep be Rerun She value sien: eae node using ree,
©) igemptyC)
chepaz Revert Seue Bd Bond == NULL
a) s_ PMO)
« Not feabbe wor Vialeed Dish 5
seples aie Waocerton 13 Kner a
Ke
—
entadtg nRS ST
Gomtinue Us int
Loith Sve gremaintn cles: with
GB Creale a program WW Cc © Amudaded & OS oa
“Awo Juewess Por Cudlomen omnwols
Process n Aspeut\Backions-
tindude Sstdiorh
H incbude wiionity= prosithys
gemp next = Null
selon hemp)
+ void eng ueue (staucr Node®* heady int dobay es ~ |
© struct Node*newNede = coreateNode( dota pnionitys
SpA head == NULL IN (head) > pniostity > Puteri y ||
mewNode ~ynext = xheads
head =newNode 5
Fasel shauck Node Xfemp= *heads
hide temp) rad !=NULL & Rtemp-pnext>
pnianite <= patos)
Paemp =teme nex} ; ity cx pay) Tf
newNode ner =temp2nexts
Femp-ynext =newNodes 3”
fnr deg ueue (struct Node** head) f
{¢ (#heod ==NuLl) nebunn +s
Souct Node* temp =*heads ?
head =(*head)-ynexts
int value =temp -ydolas
See ltempys
meet Pave 5 3
aeres ree
Void pnintduer® ne #head){
tahtlle( head | =NULY » \dash
paints Hy. (RENTS +/-d) ahead? ¢ pn ca
4 head head her's
pork “AULLN);
ink main$ oS
Slouch Node * py =NULL;
rengue ue (p97 25
eng uewel& Py. 7 574);
onguewe (&P9 7 63) Hf
paint S(t psiianity, Quened: Ny By
int - .
vata li °F { PDS a yan! dequers (Rents
sual state Queue {rn Cee \
;
pari Quen Pd); |
Nerunn 0s | |
& Tinpementada ciseron Tae
7 Hincludersidiohy | ;
vncbade csidlleshy 1 hue
Sinuct CarcubonQueve f
ink themeLS263 3 8
in Rarant » eats
>
Void tnt adi zediuene (struct Ci
ch Ci
9 -r foront =9 Yea =~L 5 euler toae
a;
int isFull (Struck Cincudond:
uewe *
setumn (27Pront-== (9 rm, estas
sy
: |int isGnoty (Stauct Cisculon®yewe* gt k
a (4-7 Bont = = bpemene sxe A)3
Void engueue (stoutt Cistcubos Queue * 2)$
1 (isFath(9)) ¢ ,
paint (“@ueue 13 edd i\o")s
9 elses
ie (isEmpty (9)) 9-2 Poront=O7
9-y neon = (9-7 nec +4)7-SIZE 5
gy Hems [9% Rear] =Vabues
panintP ("sn gerted Pectin, Value)s
oe
I int dequeue (stsuct CinculanQueve*9) {
ff (isEmpty (2))
ert eaeue 13 empty, nw)s
Hetuan 15
3 else S
int velue = 9 ihemalg rforontl
If (g-yBront ==g near’) 9 -vfrort=9-yren=
else -9-7 font = fa foont Ht) WSTZE$
netunn values
Ne
3 .
Kid digdlay@ueve (struct Cincwontueue
, ii ig. eve [g 6m ed
UX i .
Peto my a
¥ contro aucune!)
int f= 9 -PRronts
while?
painte (“4a 9 itematiy)
RSs A>Galaxy A55 5G
Val Ghee S708
BL isag rncos) bneaky
T= [I44) 7 81265
SF porintel“\o")s 9
int moinld{ :
auc Clarendon Queue %
tntHabizecdoevel&D;
engueve (89103
enguetre [&9 1203
enguevel& ax
* Queue(&LY; |
“ain [equeved TAN" aquest}
asploy, quae (22);
engueve (29, 40);
apa Quevel 895
netunnO5
3iii
yea Sheet s7e8
Ser aan 0a Woshiy Techniques __ INS
(2) Sepuentiad ov ce uo og Tecrignes Ie
Algosithm )
Seple ae ‘terete Yrowugh an ungomta aseay) onsilty
Step =Gmpane ead denen vit Whe Leaget Value ypu ene i
Shep: ny Saadeh Band oa sndexlosrorys 2%" NONE
Pointen (Binked Hi
(wb) Bineeny ‘seam 7
SAepis he
Sen cS aes Geen RP fare in sik }
Sia hee es eee Anan Sne he Pe npBeanth|
siepS: Ty we ton WN, is gather nat Nhe emdde. demett
Kane de.
Shep 6: Benvine ae, e kang VB ound on Se Beenth|
3 es em We
(©) Hashin
A
Steph ace ovsim@le haah tae stnucture (291 ON corey |
“ay Vinked %
Shoo’) Tin erent ahash yunction hod &
P an na euains an Mex within ae Sg al
: ee ayalue pein Yo She hagh lol |
steps ae sy , e and dindsContinue uit Sne remedning, -Prekbemse fi
Qe Woite aC program that ‘Smplements ane /
A Minked List The ue ||
Ace & ere Wa a ann ¥3 Gourd
as inpur EN panty wanes
sfoccouien Wo
tncbuded shit ; Oo
int "Seguenti adSeanch yom sg oe"
% fon Link i=o3 i4size. 5 1H)
WP lonnlty = =tongel) retunun 45
Nebunn Os
Sswer Nodef
int dlatay,
| Shract-Nede% next3
b
Stouck Node * crreateNede lintdata)
Stouet Node * new Nede= (skiuctNede %) mele]
pews Node -raota = a ada (Size of (stouct. Nede})s
Neushbde Snekt = NulL~
saturn new Nede
3
IML SequenticdSeorrdh Linked tet/stometNode% i
gknuct Node* cusmen t= heal; int tenrget)
cattle Cousvrent $ .
FF (cumment dota ==
cummtent= cunsent ?nes! re tehonds
neue >
Galaxy A55'5Gint min) £ ae
int choice ySize y J 2 AO at
printf “choose a stonucture (1%! inked,
Scant (“%d."y choice);
IP Cohoice ==1)¢ 2)
pain? ( “Enfen Hize of cotexs®!77
Scant" pool, &SIZ2)5 asize pints |
ink * aog1 = (int *) malloc (size
paint? (“Enter eements>”),
fonlint f=03 I< size; i+):
Seank ld”, Loswrli ds
paint? ( “Enten tosiget:”),
Sean?( “hd” » & target);
Pant (“Target ed xs in enisiay-\y” sang sy uentialSeech |
Ae
APBOY (e219 size, tenet)? GE role Got founds
Fee (any,
5 else tf (chelate ==0F
paint (“Enten- size ox Dinked Dist: ”.
Sank (“yoy Bstze)s 2
Stauct Node *head = Nu us
Struct Node left =NULL3
paint? (Enten Aements: ds
Balint 105 { key = Keys
New Necle -Y Vadlue = velue 5
NewNede ynexp=NULLS
metunn newt Neches
3
Sioruct HashTahbe® eneate Hashteabel) £
StawctHashiTaldbe* ht = (Stock Hash edble %) mallee
(Size of (Struct Wash Tabb) 5
fonintizOs i< TRBLE-Srzes TH+) ht tell]
selon hts =NULL
\oict insert (Stock HashTebabe * ht, int key ,intvebud)
tnd index =hash ley),
Slouch Nede% newwNade=emresteNide/ Key svallus)s
NewNede next sh+? reda\e Tindec]s
4 ht > tole Findex] = newNode ‘5
ink Seosch (struct Hashtable hb int key) $
int Index = hosh(key)s
Stenuct Node * curtent =ht + bobbeFindecls
While Ceumnent) £
12 (cummen} > key = =key) netunn cwretents
ues
cumrent = curse} nexts
Se ehunn ay
3int oneinG) £ ;
gtouck Vegh Talhe X ht = crete ash BNE OF
Insert (hts A,7L00)5
re 2005
Insent (hts 41,300)s :
patinke ( “yabue eden Key LeAd\"s gece)
print? “Value Yon Key 22 Z%a\n/> Seonch (hy 3
PING“ Vobue Aan Key AFA, Seareh( LLY
patintascbue dor key Qt NN”s Search Chty3))s
getunn O 5
3