Merge pull request #1366 from rbshealy/feature

Added deleteNode method
This commit is contained in:
Stepfen Shawn 2020-07-26 17:55:30 +08:00 committed by GitHub
commit 8ddbed6724
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -166,6 +166,22 @@ public class DoublyLinkedList {
current.previous = newLink; // 1 <--> newLink <--> 2(current) <--> 3
}
}
/**
* Deletes the passed node from the current list
*
* @param z Element to be deleted
*/
public void deleteNode(Link z) {
if(z.next == null){
deleteTail();
} else if(z == head){
deleteHead();
} else{ //before <-- 1 <--> 2(z) <--> 3 -->
z.previous.next = z.next // 1 --> 3
z.next.previous = z.previous // 1 <--> 3
}
}
public static void removeDuplicates(DoublyLinkedList l ) {
Link linkOne = l.head ;