Presentation is loading. Please wait.

Presentation is loading. Please wait.

Algorithm for deleting a node from a singly linked list

Similar presentations


Presentation on theme: "Algorithm for deleting a node from a singly linked list"— Presentation transcript:

1 Algorithm for deleting a node from a singly linked list
Algorithm delete (front,nodeToDelete) In: front node of linked list and node to delete Out: true if the node was deleted, false otherwise current = front prev = null while (current != null) and (current != nodeToDelete) do { prev = current current = current.next } if current == null then return false else { if prev != null then prev.next = current.next else front = front.next return true

2 Doubly Linked List Node object element prev next front tail

3 Java Class for a Node of a Doubly Linked List
public class LinearNodeDLL<T> { private LinearNodeDLL<T> next; private LinearNodeDLL<T> prev; private T element; public LinearNode( ) { next = null; prev = null; element = null; } public LinearNode (T dataItem) { element = dataItem;


Download ppt "Algorithm for deleting a node from a singly linked list"

Similar presentations


Ads by Google