Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The insert function. If there is a current item, then the insert function must t

ID: 3848529 • Letter: T

Question

The insert function. If there is a current item, then the insert function must take care to insert the new item just before the current position. Items that are already at or after the current position must be shifted rightward to make room for the new item. We suggest that you start by checking the precondition. Then shift items at the end of the array rightward one position each until you reach the position for the new item. For example, suppose you are inserting 14 at the location dataC1] in this sequence: data 3 6 9 1.1 [0] [1] [2] [3] [4] [5] current index used

Explanation / Answer

Implementing insert function:-

//this is a psudocode implementation:

Insert(List,current_index,used,data)

{

prev = used

index = used // variables for shifting elements..

while(index!=current_index)

{

List[prev] = List[index]; //means swapping values.. to the right

prev = index;

index = index-1;//decrementing index

}

List[index]=data;//value updated..

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote