Skip to content

Commit 08817da

Browse files
author
abimurugan
committed
Added poll method in Singly LinkedList
1 parent 971f5fc commit 08817da

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,17 @@ public void insertNth(int data, int position) {
334334
size++;
335335
}
336336

337+
/**
338+
* @return delete the head node and returns it's value
339+
*/
340+
public int poll() {
341+
if (head == null) return -1;
342+
343+
int headValue = head.value;
344+
head = head.next;
345+
return headValue;
346+
}
347+
337348
/**
338349
* Deletes a node at the head
339350
*/

0 commit comments

Comments
 (0)