You are on page 1of 9

HsSian M-03 MODULE 03

)wnite
t h oileust g funtttong fos single takd s
Insed fsont
)Deleke end

foat
) rsevt
ens head

naw nod

i ode
n e w n o d e
(Stsuctnode) malloc( si2 e eklstxutho))

node ino =
So
nede

net head
newnol
head =newnede

b) Delele end

Styut node *temp,*pev


mp-ad;
wle (tmp-xtsnit1=NULL)

4tmp tmpnat;

rev tep
mp mpnd

vee (emp'
pey Nat =NULL',

betuueen the akd list


&oubly nkud
&eubly ist Singe
single
9st out the dtesees with ezampie the etlowng penabtys
Explon11lustYade
nked ist
dcubly linked US

)Inset node at
the egining
node with ven valu
Deltting a
Douby Vaked st nod at hven Vallu
Sina ked list Delut
A double st s omplus t p

the nede
inked tist whN
nod odaln
ked list whexe geme data a poís 4o +h ntd
KVaul = 30
COntains s0me data a ponteh awe as thpsevioug node in
4he ist
to th nt ode in is s u t nod*Rmp,
Hemp=had
talouos soNen sed ory
in ollous a
( e p >NULL)
On Way

atuseG moB mimoy pes poo


) u s s less memony pee noe
(two polnees)
(single peint)
i) tomplnity einseten deluten compuasty inseaHen & delukn lse
pesi-titn is Dln) at knen po0sith0 n is o()
ota kaewn
l e Lempsinol =ka)
need te SoNe mem we need
batt ertosmoa Mp= ttnp- nut,
U) we

and seax Ching is not sequised, wlu geacin8 &mmory is no


inked ist olRmitodi, we A° r doubly L tmp rev next ttmp-Nt
we use siq t m p - n a t > p s tv - temp-pvev,

v ) Singy Lcan most be


Thy lan used to
implumiN Staks, fsee ltnp)
used dor Statkg huaps, binay bets
Eaplosn Dene nk ist Eploan th primitve o pesation per fom
nodt ad t Shna inkad ist
o) Ensdt
dota stutuse i t h ts onetton
AngLinked ist
wheu eoch node is tonne tded to one 0x
3es0 03 mose nodes

nodes
n e nod

node in the sinay t hos tw0eld nony


nodt (Stsutt nod 4) maltor ( sige b{ (tsuctnodo); tath
new =

setd "tsuged
+o Stove th data
*o thig
newncdo o=5; contans addug
newndo t : htod: Ipezt +his eld
liAk
t h nett nocs
headpV =neuwnok0,
neuwnolprev = nNdu;

head rewnde,
Insevhnganode ido the s
ab ons opeachon

Seoonchin a is

Displa onRN l i s
poineo vasiablo mp and
list
nSenlica nods tode th
l yfusmion as sho btleu, head nelt oth 1s
Step - Creode node usr get ne de ttmp- htad;

temp gtt nods t)


so 7
Updoto poink 4amp so that th Vakia ble mp tontains
Step topy A the Setond ntds
todemnis addres e
1mp- temp-> nezt,

had
st node of h i S1eyed i pon
addres oh
p 3wp t ield
ido
VAinble hod
AP 3
4tmp-nnt htod,
fhee fis ):

hfhquss
ioseled and obsee Arem
has heen node s dtbted
SHp Neds temp nvds S4p One 4
thsis
ten
nod fhsad RaturG

od
Retur ttmp,
mt nt nkd statk
1AM to impu

necls fsoam h ont tnd - #irwde <stdio.h


nud <alldt.h
Deting end e tht i tar be eleltd by tonsidsi
f30nt Strutt noaP
nede
va cus (asts
isnet tstble do dile nede ft d list int ino
lage 1 ist is epty. it
SAutnodi aUnk
(hst - NUUL)
yoedsstut nods nNopt;
Pindg"tot enplyl'; NODE gt noi ()
Retu NUl;
R
NODE
x - (NODE) mallot ( Si 2e eh Sta utt nod))
Cast? ist icting

hed - =NUIL)

out moy)i
)
y i d m e n )

NODE f i s s+

at t i o i t e , ?ten
m

NODE stNULL,

enP aet nodet)

p - n : frs in seut
ros 2 pelute frot \o" ),
tatt (
e a i t In"),
pint

Displag
pt o e ");
you
pvittnt
st)
void d'splay (NoDE Stan .d,ceita)

Swtth (theire)

NODE un
itm o be d u t dn"
Ast- NVLL) -
PridßC
Lato
+
caSe
s a n (8", &itm
P( 's mptyln f0nt (itkm, first
fiss4 nseat
Rtun'
pre ak;
sLun), d i l k . iont (fi*s4);
PritThe
ontad et Cos e 2
fisst:

bot
while ( u r }:NULL)
Di spl »4);
ault: enit (o)
d " ,tus-injo)
Pyiot

fscrt (NODE 4st) uginq sirqle nked


NODE dilute unton ov th Aotlownq
ist b) ton coknate wo Us5 ) indinq
that
Ravese
)
NODE P LOntatanatiog tu sts
Revessn as.LL )
sst, NoDE Ser)
NODE Ontat (NODE
Camnet deuk\"y. NODE us , m p
Gst i3 empty NODE tu
pi cu N0LC,
NuLL) t i r s : =NVLL)
Retun NULl w l e fi1st
\=

s ist
enp: s t ttmp {isst-> \iR a r > i k Ie NULL)
whle
enp o P - > i m
/dla", fhs ino) u u-> line
prit (Ttm dtl d

R tudn
un tHon Singly 1RRkad hst wth ntgn data , to
geanth an dmert
nth st that is Sov 4ed and a s hat is
it aattount (stsuut siede thund unsos t e

stuct wode + haod, iata)


itoUt-o, ool
Seasch
( sts
Node t tuns enf
=head,
=NULL) stut
wle uRnd l uYs at)= NOLL)
wkile

touxt 4 t

utuin ount,

SLL
i
spasse m a
Aotoudin
20 o
Qiven Sing Unked ists. LST-i LIST-2 al i t n oH m to
th LIST-2
O le ns Lugt-3 i contattnadion -
Void mngec)

funtton +0 mge dhe twe


nput isked i9
Sty uct nede*templ= hend1;
Strut nede * HP2
htad2
new poiajer
vad
Mp temp2
/use a
vatiable ,he adI, htrd? divecty 17w usent,
use 4hpoint
/ Do not
D*
wil node
in he two be tes
the adduss wiat10n #

nocla ¥ Kolden I =nULL


struct
Strut node tholds 2 = nUL

I ampovasy poia« va* 10 Sto14 ht adahgS Dxt noel 0 the

while tttmpl = NULL &9 4tmp)!=NULL)

Ex uts until b0th tmp' G emp) as ndt NUtl

holden tnp->Nxt

temp InLxt t m ;
tist pesat te st nocle
lonakina 1 ht nurd
o f*
l ked

(heldes tl -wvut)

st nec Seond ll point te Seiond nodt


mact th
holdts 2: t p - > i t

p
nt - heldna
p 1 holda
tmp holdo'
pe Ate at tmp' tmp
locan Tue noda
adtuS AA nodt a
th
updabrg
node, E the new nod is nsend a
4 iven node

noe on htades faked s xplsir +h widly used wadn


3t
swith diag
is s ed 1st tat always contadn
A hses liked
th st, his specia no s aled
ne a 4h on e
SpRtiad not tntin attua dade m atuded
nguhrq wn valtL iS en
heedey Rod TdRS do 4ollowng
onfains Son u nomak0about th4 dut o nods from , we nted to
st but Sual
neels t be diukel.
o the
und NtA
fhdPrevicu no
nUxt 8fpuitug nede
(lged to be diltted
th nert
mumoy
Suth a ) PCL
1 0 t d Aumbe et nods n th hsi
tst o h layt noct
to.*ht last nodi ath O
poto
that aways stuttue to e e Gnked st e intgers and wriH

actegd + rda nsA in tht st ts ves


dal eted node
peroxm * h \lou)ing
+0heAs neAin t tst
data lo ,20
f u n t i o n g
s0
poi wh

a
ncdest

iaked tiSt tu
the data
gadpu heads )Cse ale in bln the nodes hovng
widek wh
dado
Valuw is

a nods
Herdes ltked lte I n set
Valug o &20
whose data ie 20
h ndo
i) Delute
t
4vDurded Hendas ltakd fiu c i s Hejes L-L sultig g y
) Dspla
1ngt node at the beginning. INs ERT St ut N0de
ttamples ew
to
with
Ilustate A Ade th a
9iven vau
intemedi a pos:Hor, DELETE.
in dota,
anodt Styuct Node at,
at h fs0n
ntde
Aeld addid befte hiad 6{ th qiven t ard wy
oe nede s always p1v-hd", int neuw nads)
The thJ
tl hr ezi th J°n v o i i N u t Atta (stzut
No *

rede beeomes s
r htr
added odo mSat h vod,
1015-0-1 ad, we
tinkd h+ s
us tau he unthon thd pevnods
=
s uLL)
10IS9205 be NUL),
then he be Ome, 5- euive o peio node cannot
fst puekt). Thi pusht) Nug
pi 4h* qiven
a
pushmust thngo
poinks + h e u d points, pet avse
noe
Poins to point +0 t h n ew
ede e) malet (sge e (Ghwtt niod); node
Stsut Nede*nu +he Stuthoe to ouok
e nadt-> data - ntwdata, f u n t k o
topes{e ) Cuae a ist
n0de at thend
n o d e -> nert -pspv- nediat, bInsxta
D e l e s t node
) Disploy all inodes

) vodullkwode ( Struet node thuad.vt , a pestpn)


o)7eae alist
tneda

t(hedye NeLu) void neatelit îtm)


vetsn,
311 u N ede s t n * Nad.ret Stsuct nods*nadnoda,

pos tia =c)


oewode - lS+sutt nodat)
moa1lot (sizg ah (Stutnodo);

neud nodeSinto =iRm,


Thadvet tmpnoat, noclo n - NLL,
new

nod e ad +h erd
Lses1
Ao lit i-o, tmplen utl & i<po siten-1;it4
t p mp- ndit, nuwnodR

tmpN vl 1| Hng-Ntt: =nvlt) Stut necla *newnodu,

neud nods(Struut nods +) mauloc(sigeet (stut


Stuut Nede tnut:tmp-untJNt,
t e Hemp- nt), tmp-nd;
=NULu)
tmp-runt : unt wsla hnp>next !

temp mp-neat
)Display
Nedithusd)
u)veid prit(stnuut tempnAt ntw nsdo, void splayt)
Stut nodo «emp
third= NULL!
) ) Delut fist ntds tmp-ht od',
utn,
wile (4emp n o )
pnd ives[ hind >ntna)

Stut ndu * tmp


print ")d4, tmp-singos,
tenp 4tmp-na
Hemp tad,
hEad at)
htad
Opnatens
add( Sisuttaedt *h,
unctons
4o

concatanatim
tha

etuwo
fot1owinq
DLL Douby d

e h3-o
stauut nods 7 ha)
) Dll o *h qve
Reltm
13uet
nod

b)Seaoch t l he enpont his


n tam n
hige that that 6j hr Ahen the
finad stis to
going thenode
a)contadtratitn votd seoch lind kay, NODE 4isa)
be et h *
Joshloi)
345ut nods
NODE ;
heap®)a 2p)
Stsuut nods +
Sts ut nods
h3Pped (hs, ne th ot,h- eap)),
h-h t,
sutusa,

(he-o) bresk,
odombint t) Cu f i s t ,
wwile ( n ] e w o y )

ti enponsnt tuns dut to be i ghat ther mat h


St t ndi tlink Sami as hz and append to inat ist /
un-tak°) break
isteven, i Ckaye
(h-np<ha ->txp)
wie i k neut]= NULL)
h3 0ppend (hs, nunthto, ha-tzp);
L iNK-nit; h2 h nsit
pird"ganh iS
nutsstul hy ik Cha-=o) brta;
Rahun,
LAKnrt: cdå;
odd pstv=Vak, print (sesnuh is uuesstulln")

LISt tost : i k ; h3 append (h, nsuw(Ch->o«


+ a-> Lott)» h>eap))
h: h - a t ,
) u l o noes stuttst dov Lisked sepsestdabsa o ponomias. enpluin
lha -o) bitale
t alaosithn 4o add Auo Po misds pTentd sing
a4 mainy two tlds zponsnt and toethiend 1
A pounomia
Node e peunomia
xponsnt dnt i n Aoy hLl-o, kà-h2Nt) h3> appe ne C h3, neu (ha -
Tepeat as foleus lo e,ha-> ezp)
E 3x+ 5Xt w
thl=o)
for (h!>o, h= h->ad) hy: append ( h3 yntw(h~ we{ , h-sezp) p

yetuen h3
twe polynomials.
vepiesendt inkad . sts
P ard the two poy nomals
be
SHp2
wile n nct nul, sepea
P4

do not tanel

iAh Rms NO The Sum polmo maaJ


RANG
the
ninSut the Sun e

AddoneP
Adau
4ist poyromia pouwtn ét Sep
E the poweY eth irto Sum poumem
Aem st polynomia
he m
Then

ad NTO
t O Sumn
Sum pouomind
om seLond polynowki
Else ut he 4Um

int
dVen q tha non-tmply polynomual
semaining
uns om
topy the
un pelymomal.
to be po usmd tiW Hhe end
The thied sHp the agovrthm
thepoly nemial Koo not bur uchd

You might also like