We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 4
Insertion operations of Linked List
(SLL & DLL)
Insertion – at first position, in the middle& at the last
FOR INSERTION – NEW NODE HAS TO BE TAKEN FROM
AVAIL
Algorithm Newnode(INFO, LINK, AVAIL, NEW)
INFO – Part of the node that contains information LINK – Part of the node that contains address of next node AVAIL – Available space in the memory NEW – New node taken from AVAIL
Step 1: - If AVAIL=NULL print “Memory Overflow” and return
Step 2: - If AVAIL NULL then Set NEW=AVAIL Set AVAIL = LINK[AVAIL] Set INFO[NEW]=ITEM Step 3:- Return Step 4:- End InsFirst_SLL() 30/11/2024 Lecture Notes - Dr. Persis 1 INSERTION (AT FIRST POSITION) Algorithm InsFirst_SLL(INFO, LINK, START, AVAIL, NEW) Algorithm InsFirst_DLL(INFO, FORW, FIRST, AVAIL,NEW) INFO – Part of the node that contains information INFO – Part of the node that contains information LINK – Part of the node that contains address of next node FORW – Part of the node that contains address of next node START – The pointer that contain the address of first node FIRST – The pointer that contain the address of first node AVAIL – Available space in the memory AVAIL – Available space in the memory NEW – New node taken from AVAIL NEW - New node taken from AVAIL
Step 1: - Call Newnode() Step 1: - Call Newnode()
Step 2: - Set LINK[NEW] = START Step 2: - Set FORW[NEW] = FIRST Step 3:- Set START = NEW Step 3: - Set BACK[FIRST] = NEW Step 4:- Return Step 4:- Set FIRST = NEW Step 5:- End InsFirst_SLL() Step 5:- Return Step 6:- End InsFirst_DLL()
30/11/2024 Lecture Notes - Dr. Persis 2
INSERTION (AT ANY LOCATION - MIDDLE) Algorithm InsLoc_SLL(INFO, LINK, START, AVAIL, LOC,NEW) Algorithm InsLoc_DLL(INFO, FORW, FIRST, AVAIL,LOC,NEW) INFO – Part of the node that contains information INFO – Part of the node that contains information LINK – Part of the node that contains address of next node FORW – Part of the node that contains address of next node START – The pointer that contain the address of first node FIRST – The pointer that contain the address of first node AVAIL – Available space in the memory AVAIL – Available space in the memory LOC – Location of New Node LOC – Location of New Node NEW – New node taken from AVAIL NEW – New node taken from AVAIL Step 1: - Call Newnode() Step 1: - Call Newnode() Step 2: - If (LOC = 0) then Step 2: - IF (LOC=0) THEN Set LINK[NEW]=START SET FORW[NEW]=FIRST SET FIRST = NEW else Else Set LINK[NEW] =LINK[LOC-1] SET FORW[LOC-1]=NEW AND SET BACK[NEW]=LOC-1 Step 3:- Set LINK[LOC-1]= NEW SET FORW[NEW] = LOC+1 AND BACK[LOC+1]=NEW Step 4:- Return Step 3:- Return Step 5:- End InsLoc_SLL() Step 4:- End InsLoc_DLL() Loc-1 Loc+1
Node 3
30/11/2024 Lecture Notes - Dr. Persis 3
INSERTION (AT THE END –LAST NODE) Algorithm InsLast_SLL(INFO, LINK, START, AVAIL, NEW) Algorithm InsLast_DLL(INFO, FORW, FIRST, AVAIL, NEW) INFO – Part of the node that contains information INFO – Part of the node that contains information LINK – Part of the node that contains address of next node FORW – Part of the node that contains address of next node START – The pointer that contain the address of first node FIRST – The pointer that contain the address of first node AVAIL – Available space in the memory AVAIL – Available space in the memory NEW – New node taken from AVAIL NEW – New node taken from AVAIL
Step 1: - Call Newnode() Step 1: - Call Newnode()
Step 2: - Set PTR = FIRST Step 2: - Set PTR = START Step 3:- Repeat Step 4 until (PTR LAST) Step 3:- Repeat Step 4 until (PTR NULL) Step 4:- Set PTR =FORW[PTR] Step 4:- Set PTR =LINK[PTR] Step 5:- Set FORW[PTR]=NEW Step 5:- Set LINK[PTR]=NEW Step 6:- Set BACK[NEW]=PTR Step 6:- Set LINK[NEW]=NULL Step 7:- Set FORW[NEW]=LAST Step 7:- Return Step 8:- Return Step 8:- End InsLast_SLL() Step 9:- End InsLast_DLL()