Implement the removeAtPosition function of the LinkedList class . bool LinkedList::removeAtPosition(int position) The job of this function is to remove the node at the given
Implement the removeAtPosition function of the LinkedList class .
bool LinkedList::removeAtPosition(int position)
The job of this function is to remove the node at the given position.
If given a position in legal range, the function will remove the node at that position, reduce the length by 1 and return true . For example, if the list is initially { 1, 2, 3 } and we call removeAtPosition(2) then the list will be changed to { 1, 3 }, length will be decreased from 3 to 2 and true will be returned.
If position is less than 1 or greater than length then the function should leave the list unchanged and return false .
Note that removing a node at position 1 requires that the headPtr be updated. In that case you may want to just call removeFirst to do the work for you.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started