Technical Interview

Tips, questions, answers and puzzles at
www.technical-interview.com

Thursday, April 22, 2010

Singly Linked List – Delete Node

Q:

You are given a pointer to a node (not the tail node) in a singly linked list. Delete that node from the linked list. Write code in C.

A:

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

No comments:

Post a Comment