We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 308bdcf commit 016f050Copy full SHA for 016f050
src/main/java/com/thealgorithms/datastructures/lists/SinglyLinkedList.java
@@ -383,6 +383,17 @@ public int getNth(int index) {
383
return cur.value;
384
}
385
386
+ // poll method is used to remove the head elemnt and return its value
387
+ public int poll() {
388
+ if (head == null) {
389
+ return -1; // Return a default value or handle empty case
390
+ }
391
+ int headValue = head.value;
392
+ head = head.next;
393
+ size--; // As head is removed size will be decreased
394
+ return headValue;
395
396
+
397
/**
398
* @param position to check position
399
* @param low low index
0 commit comments