Frage im Vorstellungsgespräch bei Yahoo

How do you remove a node from a singly linked list, given only that node? (no head)

Antworten zu Vorstellungsgespräch

Anonym

10. Okt. 2013

Copy the data and pointer from the next node into the given node.

Anonym

12. März 2017

public class delNode { public static Node head = new Node(10); public static void main(String[] args) { // TODO Auto-generated method stub head.next = new Node(13); head.next.next = new Node(15); head.next.next.next = new Node(18); delete(head.next); while(head!=null) { System.out.println(head.data); head = head.next; } } public static void delete(Node n) { n.data = n.next.data; n.next = n.next.next; } }