Interview Question

Financial Software Developer 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.
Tags:
technical, algorithm
Answer

Interview Answer

2 Answers

0

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
2

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 Question, Sign In with Facebook or Sign Up