Algorithm for inserting an element to an array





Algorithm:



(Inserting into a Linear Array) INSERT(LA,N, K, ITEM)


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.



Comments

Popular posts from this blog

Node.js Cheat Sheet

Codeigniter ! Simple But Powerful

Enhancing Supply Chain Security and Cloud-Native Development with Chainguard