Given a singly linked list where each node represents a character including special characters, the task is to remove all the occurrences of special characters from the linked list so that only valid characters are present in the linked list.
Input: List = ( -> G -> E -> E -> * -> K -> S -> * -> NULL
Output: G -> E -> E -> K -> S -> NULL
Input: A -> B -> C -> * -> @ -> NULL
Output: A -> B -> C -> NULL
Approach: Traverse the linked list, if the current node’s data is a special character then make the next of the previous node point to the next of the current node. Do this for every node with a special character and finally print the updated list.
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.
- Reverse nodes of a linked list without affecting the special characters
- Remove all Fibonacci Nodes from a Circular Singly Linked List
- Remove all the Even Digit Sum Nodes from a Circular Singly Linked List
- Remove all even parity nodes from a Doubly and Circular Singly Linked List
- Difference between Singly linked list and Doubly linked list
- Convert singly linked list into circular linked list
- Remove the common nodes in two Singly Linked Lists
- Convert Singly Linked List to XOR Linked List
- Sum of the nodes of a Singly Linked List
- QuickSort on Singly Linked List
- Circular Singly Linked List | Insertion
- Binary Search on Singly Linked List
- Alternate Odd and Even Nodes in a Singly Linked List
- Insertion Sort for Singly Linked List
- Convert a Singly Linked List to an array
- Alternating split of a given Singly Linked List | Set 1
- Product of the nodes of a Singly Linked List
- Implement a stack using singly linked list
- Reverse a singly Linked List in groups of given size | Set 3
- Various operations on Fibonacci nodes in a Singly 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.