Skip to content

Commit 26d8cb6

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

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

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

+13
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,19 @@ 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) {
342+
return -1;
343+
}
344+
345+
int headValue = head.value;
346+
head = head.next;
347+
return headValue;
348+
}
349+
337350
/**
338351
* Deletes a node at the head
339352
*/

0 commit comments

Comments
 (0)