Given a linked list, print the alternate nodes of linked list.
Input : 1 -> 8 -> 3 -> 10 -> 17 -> 22 -> 29 -> 42 Output : 1 -> 3 -> 17 -> 29 Alternate nodes : 1 -> 3 -> 17 -> 29 Input : 10 -> 17 -> 33 -> 38 -> 73 Output : 10 -> 33 -> 73 Alternate nodes : 10 -> 33 -> 73
1. Traverse the whole linked list.
2. Set count = 0.
3. Print node when count is even.
4. Visit the next node.
8 11 12
Time Complexity : O(n)
Auxiliary Space : O(1)
Asked in : Govivace
- Reverse alternate K nodes in a Singly Linked List - Iterative Solution
- Print alternate nodes of a linked list using recursion
- Print the last k nodes of the linked list in reverse order | Iterative Approaches
- Sum of the alternate nodes of linked list
- Product of the alternate nodes of linked list
- Alternate Odd and Even Nodes in a Singly Linked List
- Delete alternate nodes of a Linked List
- Subtraction of the alternate nodes of Linked List
- Reverse alternate K nodes in a Singly Linked List
- Given a linked list, reverse alternate nodes and append at the end
- Print nodes of linked list at given indexes
- Print the last k nodes of the linked list in reverse order | Recursive approach
- Merge a linked list into another linked list at alternate positions
- An interesting method to print reverse of a linked list
- Alternate sorting of Linked list
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.