write an algorithm to insert an element in an array
Answers
Answered by
2
Explanation:
This algorithm inserts an element ITEM into the Kth position in LA.
[Initialize Counter] Set J: = N.
Repeat steps 3 and 4 while J ≥ K.
[Move Jth element downward] Set LA [J+1]: = LA [J]
[Decrease Counter] Set J: = J-1. [End of step 2 loop]
[Insert element] Set LA [K]: = ITEM.
[Reset N] Set N: = N+1.
Exit.
Answered by
1
Answer:
This algorithm inserts an element ITEM into the Kth position in LA.
[Initialize Counter] Set J: = N.
Repeat steps 3 and 4 while J ≥ K.
[Move Jth element downward] Set LA [J+1]: = LA [J]
[Decrease Counter] Set J: = J-1. [End of step 2 loop]
[Insert element] Set LA [K]: = ITEM.
[Reset N] Set N: = N+1.
Exit.
Similar questions