Page 276 - computer science (868) class 11
P. 276

Step 1:  There is no interchange in the first three numbers as they are already in descending order. Thus, the third and
                      fourth elements are checked.

                                   Index        0           1           2          3           4
                                    Ar          16          12         10          21          2

                      Since, ar[2] < ar[3], i.e., 10 < 21 is true; the numbers are swapped.
                      Swapping the numbers in the position, the array becomes:

                                   Index        0           1           2          3           4
                                    Ar          16          12         21          10          2

              Step 2:  Next two elements are compared.
                                   Index        0           1           2          3           4

                                    Ar          16          12         21          10          2
                      Since, ar[3] < ar[4], i.e., 10 > 2 is false; there will be no interchange.
                      With this, the second smallest number is placed in the second last position.


              Iteration 3:
                                   index        0           1           2          3           4
                                    Ar          16          12         21          10          2

              Step 1:  There is no interchange in the first two numbers as they are already in descending order. Thus, the second and
                      third elements are compared.
                                   Index        0           1           2          3           4

                                    Ar          16          12         21          10          2
                      Since, ar[1] < ar[2], i.e., 12 < 21 is true; the numbers are swapped.

                      Swapping the numbers in the position, the array becomes:
                                   Index        0           1           2          3           4

                                    Ar          16          21         12          10          2
              Step 2:

                                    Ar          16          21         12          10          2
                      There is no interchange in the last three numbers as they are already in descending order.


              Iteration 4:
              Step 1:  First two elements are compared.

                                   index        0           1           2          3           4

                                    Ar          16          21         12          10          2
                      Since, ar[0] < ar[1] , i.e., 16  < 21 is true; the numbers are swapped.

                      Swapping the numbers in the position, the array becomes:
                                   index        0           1           2          3           4

                                    Ar          21          16         12          10          2


                274274  Touchpad Computer Science-XI
   271   272   273   274   275   276   277   278   279   280   281