+ 1

Why do we increment N by 1 after inserting an item to the mid of the array in Data Structure?

Algorithm (Inserting Into a Linear Array) INSERT (LA, N, K, ITEM). Note: LA is a linear array, N is it's length and K is the position where ITEM will be added. Step 1) SET J = N. Step 2) REPEAT Step 3 & 4 While J > = K. Step 3) SET LA[J+1] = LA[J]. Step 4) SET J = J - 1. Step 5) SET LA[K] = ITEM. Step 6) SET N = N + 1. Step 7) END

28th Oct 2017, 6:19 PM
Esmatullah Sayeedy
Esmatullah Sayeedy - avatar
1 ответ
+ 8
beacuse you have to increment index of array to put something on first position of array(0 index), then on second and so on
12th Nov 2017, 12:18 PM
Vukan
Vukan - avatar