Interview Questions and Answers :: Adobe
Home > Experience Archives > Adobe > Interview Question Set 1 > Discussion
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.
Amarjit
9 Apr, 2017 1:20 PM
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.
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.
Report Error
Report Error
Please Login First Click Here