Function DELETE (TEMPHEAD, KEY)
[This Function delete an element from the doubly list and returns the address of the first element TEMPHEAD is pointer which points the first element of the list and KEY specify info of the node which is to be deleted]
1. [Check for the empty list]
If TEMPHEAD = NULL
Then write (“Empty list”)
Return
2. [Deletion of the first node]
TEMP = TEMPHEAD
RPTR (TEMPHEAD) = TEMPHEAD
PRV (TEMPHEAD) = NULL
Free (TEMP)
Return (TEMPHEAD)
3. [Save the address of the first node]
SAVE = TEMPHEAD
4. [Search for the desire node]
Repeat while thru step 5 RPTR (SAVE)! = NULL
5. [Check for the information field]
If INFO (RPTR (SAVE)) = KEY
Then TEMP = RPTR (SAVE)
RPTR (SAVE) = RPTR (RPTR (SAVE))
LPTR (RPTR (SAVE)) = SAVE
Free (TEMP)
6. [Finished]
Return (TEMPHEAD)
No comments:
Post a Comment