Given the linked list representation of a string, the task is to swap every subsequent pair of vowels in it to produce the resultant linked list.
Input: List = g -> e -> e -> k -> s -> NULL
Output: g -> e -> e -> k -> s -> NULL
The only vowels are ‘e’ and ‘e’ which
will be swapped with each other.
Input: List = a -> b -> c -> d -> e -> NULL
Output: e -> b -> c -> d -> a -> NULL
- Use two pointers of linked list node type for storing the node with the first vowel and for traversing the linked list respectively.
- Start traversing the linked list till the end.
- If a vowel is encountered and the first pointer already contains a node with a vowel in its data part, then swap the contents of the current node and the first node and the set the first pointer to NULL.
- In case a vowel is encountered and the first pointer does not contain anything, set the first pointer to point to this node.
- In case the vowel is not encountered, continue the traversal.
Below is the implementation of the above approach:
g -> e -> e -> k -> s -> NULL
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.
- Arrange consonants and vowels nodes in a linked list
- Program to remove vowels from Linked List
- Swap Kth node from beginning with Kth node from end in a Linked List
- Pairwise swap elements of a given linked list by changing links
- Swap nodes in a linked list without swapping data
- Pairwise swap adjacent nodes of a linked list by changing pointers | Set 2
- Swap Kth node from beginning with Kth node from end in a Doubly Linked List
- Pairwise swap elements of a given linked list
- Linked List representation of Disjoint Set Data Structures
- XOR Linked List - A Memory Efficient Doubly Linked List | Set 1
- XOR Linked List – A Memory Efficient Doubly Linked List | Set 2
- Merge a linked list into another linked list at alternate positions
- Convert singly linked list into circular linked list
- Difference between Singly linked list and Doubly linked list
- Convert Singly Linked List to XOR Linked List
- Create new linked list from two given linked list with greater element at each node
- Check if a linked list is Circular Linked List
- Generate Linked List consisting of maximum difference of squares of pairs of nodes from given Linked List
- Construct a Maximum Sum Linked List out of two Sorted Linked Lists having some Common nodes
- Create a linked list from two linked lists by choosing max element at each position
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.
Improved By : GauravRajput1