diff --git a/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java b/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java index d5d3f31f4b66..c97671f890b4 100644 --- a/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java +++ b/src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java @@ -347,7 +347,23 @@ public void deleteHead() { public void delete() { deleteNth(size - 1); } - + + /** + * Returns the head(first node) isolated and removes it from the + * Linked-List + * Updates the size of Linked-List + */ + public Node poll() { + if (this.head == null) + throw new NoSuchElementException(); + else { + Node destruct = head; + head = head.next; + destruct.next = null; + size--; + return destruct; + } + } /** * Deletes an element at Nth position */