Delete a Linked List node at a given position

Linked list is collection of element. Some of case we are need to delete unknown linked list element which are exist of given position. This position is decided by index value. For example same as an array element. But in linked list there are not possible to get random element by index position.

Approaches: As we say that there is not possible to get random element of linked list. But help of head pointer (first linked list nodes) we can iterators linked list node are one by one. So applied this similar logic to get linked list element which are exist in nth position.

Test cases: Before write an algorithm, consider following test cases.

1) When linked list are empty that means we can not find index position.

2) We are Assume that the first linked list node are at index 1 position. And given position are positive value.

Linked list: 1  9  5  8
Index      : 1  2  3  4

3) There is possible to given index position are not exist in linked list so in this case display a message (Given index are invalid or invalid position).

Suppose linked list contain following (10, 20,30, 40, 50, 60, 70, 80) nodes.

Linked List After Remove node position 5

Here mentioned list of solution which is target to particular language.



Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved