ALGORITHM FOR INSERTION IN ARRAY AT BEGINNING AND END:
INSERT_BEG(LA,LB,UB,ITEM): Here LA is a linear array with lower bound LB and upper bound UB. This algorithm insert an element ITEM at the beginning of the linear array LA.
INSERT_END(LA,LB,UB,ITEM): Here LA is a linear array with lower bound LB and upper bound UB. This algorithm insert an element ITEM at the end of the linear array LA.
INSERT_BEG(LA,LB,UB,ITEM): Here LA is a linear array with lower bound LB and upper bound UB. This algorithm insert an element ITEM at the beginning of the linear array LA.
- Set I = UB
- Repeat steps 3 and 4 while I >= LB
- Set LA[I+1] = LA[I]
- Set I = I-1
- Set LA[LB] = ITEM
- Set UB = UB+1
- Exit
INSERT_END(LA,LB,UB,ITEM): Here LA is a linear array with lower bound LB and upper bound UB. This algorithm insert an element ITEM at the end of the linear array LA.
- Set I = UB
- Set I = I+1
- Set LA[I] = ITEM
- Set UB=UB+1
- Exit