Saturday, 24 September 2016

INSERTION IN ARRAY AT BEGINNING AND END

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.
  1. Set I = UB
  2. Repeat steps 3 and 4 while I >= LB
  3. Set LA[I+1] = LA[I]
  4. Set I = I-1
  5. Set LA[LB] = ITEM
  6. Set UB = UB+1
  7. 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.
  1. Set I = UB
  2. Set I = I+1
  3. Set LA[I] = ITEM
  4. Set UB=UB+1
  5. Exit 

No comments:

Post a Comment

POLYMORPHISM IN C++

POLYMORPHISM IN C++ C++ achieves polymorphism through: i) Function overloading ii)Operator overloading By the...