/* * Implement an algorithm to delete a node in the middle of a single linked list, given only access to that node * EXAMPLE * Input: the node ÔcÕ from the linked list a->b->c->d->e * Result: nothing is returned, but the new linked list looks like a->b->d->e */ public void deleteNode(LList list, LList.Node c) { if ((null == list) || (null == c)) return; LList.Node n = list.head; if (n == c) { System.out.println("1:"); list.head = list.head.next; return; } LList.Node nP = list.head; n = n.next; while (null != n) { System.out.println("2:"); if (n.data == c.data) { System.out.println("3:"); nP.next = c.next; // VB, it should be nP.next = n.next c.data = null; // n.data = null c.next = null; // n.next = null return; } nP = n; n = n.next; } }