197k views
4 votes
If we want to create a single function for insertion and deletion in the linked list, Suggest any approach by which this task can be carried out. Just verbally explain how we can accomplish this, no need to write the code

User Henryabra
by
4.0k points

1 Answer

5 votes

Answer:

Step-by-step explanation:

One approach to this would be to create the function with two parameters. One would be the element to be added or deleted while the other would be a char variable that would indicate the process to be completed (adding or deleting). This char can have a value of '+' or '-' accordingly. Then within the function, we would use an IF/Else statement to detect whether the char variable had a value of '+' or '-'. If the value was '+' we would execute the insertion process of the code but if the value was '-' we would only execute the deletion process of the code. Therefore, allowing both processes to be available within a single function.

User Eugene Shtoka
by
4.5k points