Page 378 - CA_Blue( J )_Class10
P. 378

Step 1:

                                            index     0       1       2       3       4
                                             ar      12      51      10      44
              First, it is to be check whether index 2 is there in the array or not.

              Step 2:
                                            index     0       1       2       3       4
                                             ar      12      51      10      44




              The element in index 3 will be copied to the next index 4.
              The element in index 2 will be copied to the next index 3.
              Step 3:

                                            index     0       1       2       3       4
                                             ar      12      51      10      10      44

              Then in the index the element 20 will be inserted.
                                            index     0       1       2       3       4
                                             ar      12      51      20      10      44


              15.5.4 Deletion
              To delete an element in any position of the array, it is required to check whether the index is there in the array or not.
              Then shift the element next to the index position to the deletion index position. In this way, all the element in the right
              of the deletion index will be shifted one index to left till the last. And the last element will be replaced by zero.

              Let us take an example in which the number to be deleted is 10 in the index position 2.
                                            index     0       1       2       3       4
                                             ar      12      51      10      44      25

              Step 1:

                                            index     0       1       2       3       4
                                             ar      12      51      10      44      25
              First, it is to be check whether index 2 is there in the array or not.

              Step 2:
                                            index     0       1       2       3       4
                                             ar      12      51      44      25      25

              The element in index 3 will be copied to the previous index 2.

              The element in index 4 will be copied to the previous index 3.
              Step 3:

                                            index     0       1       2       3       4
                                             ar      12      51      44      25       0

              Then, in the last index, element 25 will be replaced by 0.


                376376  Touchpad Computer Applications-X
   373   374   375   376   377   378   379   380   381   382   383