Inserting Into a Linear Array
Algorithm: (Inserting into a Linear Array) INSERT (LA, N, K, ITEM)
Here LA is a linear array with N elements and K is a positive integer such that K < N. This algorithms inserts an element ITEM into the Kth position in LA.
1. [Initialize Counter.] Set J : = N.
2. Repeat Steps 3 and 4 while J > K.
3. [Move Jth element downward.] Set LA[J + 1] : = LA[J].
4. [Decrease Counter.] Set J = J-1.
[End of Step 2 loop]
5. [Insert Element.] Set LA[K] : = ITEM.
6. [Reset N.] Set N : = N + 1.
7. Exit.
If You want to learn about the technology, computer science & engineering, web programming, freelancing, earning please click here :CSE SOLVE
Algorithm: (Inserting into a Linear Array) INSERT (LA, N, K, ITEM)
Here LA is a linear array with N elements and K is a positive integer such that K < N. This algorithms inserts an element ITEM into the Kth position in LA.
1. [Initialize Counter.] Set J : = N.
2. Repeat Steps 3 and 4 while J > K.
3. [Move Jth element downward.] Set LA[J + 1] : = LA[J].
4. [Decrease Counter.] Set J = J-1.
[End of Step 2 loop]
5. [Insert Element.] Set LA[K] : = ITEM.
6. [Reset N.] Set N : = N + 1.
7. Exit.
0 comments:
Post a Comment