Algorithm to Delete a Node from the Doubly Linked List

Algorithm to delete a node from the end

Step 1: IF HEAD = NULL

Write UNDERFLOW

Go to Step 7

[END OF IF]

Step 2: SET TEMP = HEAD

Step 3: REPEAT STEP 4 WHILE TEMP->NEXT != NULL

Step 4: SET TEMP1=TEMP

Step 4: SET TEMP = TEMP->NEXT

[END OF LOOP]

Step 5: SET TEMP1 -> NEXT = NULL          

Step 6: FREE TEMP

Step 7: EXIT


Algorithm to delete a node from the front

 STEP 1: IF HEAD = NULL

WRITE UNDERFLOW

GOTO STEP 6

STEP 2: SET TEMP = HEAD

STEP 3: SET HEAD = TEMP → NEXT

STEP 4: SET TEMP → PREV = NULL

STEP 5: FREE TEMP

STEP 6: EXIT

 

Algorithm to delete a node from the specific position

 STEP 1: IF HEAD = NULL

WRITE UNDERFLOW

                GOTO STEP 11

                END OF IF

STEP 2: SET TEMP = HEAD

STEP 3: SET I = 0

STEP 4: REPEAT STEP 5 TO 8 UNTIL I<LOC

STEP 5: TEMP1 = TEMP

STEP 6: TEMP = TEMP → NEXT

STEP 7: IF TEMP = NULL

WRITE "DESIRED NODE NOT PRESENT"

                GOTO STEP 11

                END OF IF

STEP 8: SET I = I+1

END OF LOOP

STEP 9: TEMP1 → NEXT = TEMP → NEXT

STEP 10: FREE TEMP

STEP 11: EXIT