Created
February 12, 2013 15:35
-
-
Save charlespunk/4770708 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Implement an algorithm to delete a node in the middle of a singly linked list, given only access to that node. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static boolean deleteNode(Node node){ | |
if(node == null || node.next == null) return false; // could not be done when the next node is null | |
node.data = node.next.date; | |
node.next = node.next.next; | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment