Logo 
Search:

C++ Programming FAQ

Submit Interview FAQ
Home » Interview FAQ » C++ ProgrammingRSS Feeds

Write an algorithm for Deleting a Node using Singly Linked List in dfs (data file structure).

  Shared By: Lurline Fischer    Date: Dec 12    Category: C++ Programming    Views: 8765

Answer:

PROCEDURE DELETE (T, KEY)
[Where ‘head’ pointer has been caught in pointer ‘T’ & the value in ‘key’]

1. [Checking for deletion of first node and deleting]

if (DATA(T) == KEY)
P <-- T
T <-- LINK (T)
Call REMOVE NODE(P)
return (T).

2. [Traversing to the destination node]

I <-- T
while (DATA (LINK(T)) != key)
if (LINK (LINK(T)) == 0)
return (0)
else
T <-- LINK(T))

3. [Deleting the target node]

C <-- LINK(LINK (T)
Call REMOVE NODE (LINK(T))
LINK (T) <-- C

4. [FINISH]
return.

Share: 
 
Comment #1  Commented By: Asad Ali   Commented On: Dec 25

what is the meaning of this P <-- T , T <-- LINK (T) in the algorithem.kindly tell me please.

 


Related Topics:

Your Comment
  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].


Tagged: