Skip to content

Commit 2607dce

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

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

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

+12
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,18 @@ 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+
int headValue = head.value;
345+
head = head.next;
346+
return headValue;
347+
}
348+
337349
/**
338350
* Deletes a node at the head
339351
*/

0 commit comments

Comments
 (0)