0% found this document useful (0 votes)
28 views6 pages

Doubly Linked List

The document provides algorithms for inserting and deleting nodes in a doubly linked list, detailing steps for adding nodes at the beginning and end, as well as removing nodes from both ends. It emphasizes checking for available space before insertion and ensuring proper pointer adjustments during deletion. The instructions are presented in a step-by-step format for clarity.

Uploaded by

Rajesh Dalvi
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)
28 views6 pages

Doubly Linked List

The document provides algorithms for inserting and deleting nodes in a doubly linked list, detailing steps for adding nodes at the beginning and end, as well as removing nodes from both ends. It emphasizes checking for available space before insertion and ensuring proper pointer adjustments during deletion. The instructions are presented in a step-by-step format for clarity.

Uploaded by

Rajesh Dalvi
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/ 6

PAGE No.

DATE

DOublykigked LISt- Tnsution,

L hsention ot the beginning


Algonilhn:i
Slept: JF AVAIL NVLL
WRITE OVER Flou
bao
9dtioic3& DEND OF T F U
3tep 2: SGT NEW_NODE AVA9d 2UI5001
3tp 3: SeT AVAlL =AV AIL NEXT
Stp 4: SET NEW_NODE >DATA -VAL
Sto 5: SET NEW_NODE >PREV ENULL
Step 6: sEr NEWN- NOPE S NEYT START

Sp 9ESTART NEW-NODE
S4ep ExT TSA12

Consider the doubly linked iSt:


START

to add Q new node


0de with do+a 0 05
the hrst rode of he ist;
Check if_ Cvailablespoce
PAGE N.

DATE

Step l: Alocoe nemong gpae i Prom aval Por newnode


Tp
Ond nitiauze its dota por to '
PREV to NLL

Siep2: Ada he ntw node be fore the Stat node.Wow


ibe oms the Arst rode df he l3
the .neLonode beomes lst
The sta auintt will NuS ho<d the 4ddnè[s af Hhe

START
2|x

SuCresfuty addg element at the beqihoin he


doubly (inked list

Ingertion at. he end.

Alqonith m: Stepi: IF AVAIL NULL


Wnte pveREhO
Go to Sttp ll
yd isicr LENDOF1F)t

Stp3: 3CT AVALL AVAINCXT


Stp 4' SETNEW.NODE DATAYAL
Step 5 SET NCJ-NoENÉxT =NULLUL
StT PTR= START
Strpt: Repeat Step 8 whe PIR >NCXT-NULL
Stép8:ttpIR -PTR NGxT COND OF LO9P
NLQtep : SLTPRINEXT FNEiNODE 9
Siep 10: SET NEw_NODE PRCV pIR
-PR
SAco 1EXIT
PAGE No.

DATE

Considé the douhly tinked l'st


341

T we
IF twant ko add a new nde With data 4 a6 the
agt node df the tist

Checc whether wR have vailoble space. for a ne) node


Step Allontt meooNy for the newnode and iniHdli ze.
its DATA Part o 4 and ils NET to NULL

4X
SHep 2i wetakeranoioter VaviablePTR and initiuze it
with START, In the while 100p we thavetse thrOugh
the linced lis fo rtach the ost Dgde
TDitiatization:
5TART
PR
Trartlse

START PrR
Step 3: Add the netonode aftr the ode pointed by PTR.
set the Prev of the newnode to PTR( node pointd
by p1R)

START

Sucues Sftuy. a005 the node )ith va 4 ds the


ed the(ist át the erd of a doubly (ine tist
PAGE Na.

DATE

Q6 Doubls_link ListDelethon
A Deletion a Beqinmin
Alqorithm:

WhiteaNDERFLO&
Go to Sttp6 -
CEND OF IF]
Sitp 3:ScT START =STA RI >NXT
0oin3t0 96TnSTAPT PR¬V =NUL Lo 1
Sttp 5: ree PTR
Step 6: ExIt

Conslder ne doubly linted ist 34 10


START

weE want to delett a node from the beginning of the


líst.:

we chect if the linked ist exiStS or hOt. I there art no


Stept:
nodes then the Erit gtQmnf isposseo
Se62:I thertrtNdeg inthe lise, we useta
pointr YOMable PTR tharis se ta point to the
First node of the i'st 0

PIR
the PTR SUes he addes the fiist rode Of th list
Tnttay
PAGE No.

DATE

Atp 3: SrAPT is úde to point to the nexL node in


START

Sier h Finally themenory oCtupled by PTR (intay the


Aus node ot liS) Ated fom memy
START

And the PREV of STAR1 iS made io Paint touwoids nothino

Firglls deleing an eement Rom the beginning of


a doubis linred list

2 Deletion ar the endal

Algontn
Stp li IE STARLs NULL
Wnitt UNpERFLOW
Go to Sttpt
LEND OF 1E]
Sep 2: 3ETPTR STAR
Stp 3:Repeat stp 4 while PIRNÊKT NULL
QET PR= PTR>NEXTiab
CEND OF LOP
Step 5- STTPIR pRCV NEXT =NULL
Stp6: FREC PTR
Stp: Eyxit
PAGE No.

DATE

Onsder the doubly Linked lis t


START

delele he tos rode from the linked


li6t
Wechecy if there ore nodeg to be deleBed ,ifno Hhen exit
S+tp!: lare a poino vGiable PTR that points to the irst
nOde of the lst. Initiaize it STAgT
START

PTR
Srp 2: MOre PTR that it oins to the ast node of
the tist

IxSART J
2 J
Sp3 We Can 0ccess he Second lag node by ta Einq ifts
addiess fpm he PRÊV of laSt Ie. To deeie e
last node, we se the NEkr of the second las ngle to
NULmating t the new lost hode of the ist
lost red
nod The menroy 0E the prtvious last node is Grtea
by freing the PTR Dhh points omds it

START

Sucessfuly uh
doubly iired ist
node at the end a

You might also like