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
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- 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
- Alternate Odd and Even Nodes in a Singly Linked List
- Product of the alternate nodes of linked list
- Subtraction of the alternate nodes of Linked List
- Delete alternate nodes of a Linked List
- Given a linked list, reverse alternate nodes and append at the end
- Reverse alternate K nodes in a Singly Linked List
- 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
- Alternate sorting of Linked list
- An interesting method to print reverse of a linked list
- Rearrange a linked list in to alternate first and last element
- Append odd position nodes in reverse at the end of even positioned nodes in a Linked List
- Splitting starting N nodes into new Circular Linked List while preserving the old nodes
- Iterative Merge Sort for Linked List
- Iterative selection sort for 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 email@example.com. 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.