[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.
Interview Questions and Answers :: Adobe

5. Write a program to delete a node in single linklist, if address of that node is given.

Answer:

There will be three scenario, depending upon the address of node is given
1. if the node is head
2. if the node in middle or any position i.e one node is next to it.
3. if the given node is last node.

1. if the node is head
head = node->next;
free (node)

2. if the node in middle or any position i.e one node is next to it.
copy the next node information to given node and delete the next node.
node->data = node->next->data;
node->next=node->next->next;
free(node->next)

3. if the given node is last node.
In single linked list operation not possible.

Post Your Answer Here:      Public      Private

Rate This: +1 -0
Report     

Post Your Reply Here:     

Report Error

Report Error

Please Login First Click Here