Arista Networks Interview Question

delete all the nodes in a linked list with a specific value

Interview Answers

Anonymous

May 22, 2012

key is to handle the head changes and the case of all nodes match.

Anonymous

Aug 22, 2012

//Assume lp contains the pointer to linked list struct link_p { int info; struct link_p *link; } lp; struct link_p *c; //to traverse the list //Find the first non-matching node in the list c = lp; while ((c != null) && (c.info == value) { c = c->next; // move the pointer ahead lp = c; // update the list pointer to the first new node } // traverse the list from now until the end of list while (c->next != null) { if (c->next.info == value) { // delete the next node c->next = c->next->next; c = c->next; } } }