Interview Question

Interview New York, NY

There is a linked list, only given the pointer of one node

  , how to delete that node in the linked list.
technical, algorithm

Interview Answer

2 Answers


I guess it refers to a single linked list. iterate unti item->next = toDelete, item->next = toDelete->next, delete(toDelete).

ektor on Sep 12, 2012

void deleteNode(struct node *node_ptr) { struct node *temp = node_ptr->next; node_ptr->data = temp->data; node_ptr->next = temp->next; free(temp); }

Anonymous on Oct 5, 2012

Add Answers or Comments

To comment on this, Sign In or Sign Up.