Page 375 - CA_Blue( J )_Class10
P. 375

Swapping the numbers in the position, the array becomes:

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

                                              index     0       1       2       3       4
                                                ar      51      10      44     124      21

                 Since ar[1] > ar[2], i.e., 124 > 10 is true.
                 Swapping the numbers in the position, the array becomes:

                                              index     0       1       2       3       4
                                                ar      51      10      44      21     124
                 After the first iteration, the largest element is placed in the last.


                 Iteration 2:
                 Step 1:
                                              index     0       1       2       3       4
                                                ar      51      10      44      21     124

                 Since ar[0] > ar[1], i.e., 51 > 10 is true.
                 Swapping the numbers in the position, the array becomes:

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

                                              index     0       1       2       3       4
                                                ar      10      51      44      21     124

                 Since ar[1] > ar[2] , i.e., 51 > 44 is true.
                 Swapping the numbers in the position, the array becomes:

                                              index     0       1       2       3       4
                                                ar      10      44      51      21     124

                 Step 3:
                                              index     0       1       2       3       4
                                                ar      10      44      51      21     124
                 Since ar[1] > ar[2], i.e., 51 > 21 is true.

                 Swapping the numbers in the position, the array becomes:

                                              index     0       1       2       3       4
                                                ar      10      44      21      51     124
                 After the second iteration, the second largest element is placed in second last position.







                                                                                                                       373
                                                                                                              Arrays   373
   370   371   372   373   374   375   376   377   378   379   380