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

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

                                     index         0          1           2           3           4

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

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

                                       Ar         16          2           12         10          21
                 Step 2:  Next two elements are compared.

                                     Index         0          1           2           3           4

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

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

                                       Ar         16          12          2          10          21
                 Step 3:  Next two elements are compared.

                                     Index         0          1           2           3           4

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

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

                                       Ar         16          12          10          2          21
                 Step 4:  Next two elements are compared.

                                     Index         0          1           2           3           4

                                       Ar         16          12          10          2          21
                        Since, ar[3] < ar[4], i.e., 2 < 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          10         21           2

                 After the first iteration, the smallest element is placed in the last position.

                 Iteration 2:
                                     Index         0          1           2           3           4

                                       Ar         16          12          10         21           2





                                                                                                                       273
                                                                                                              Arrays   273
   270   271   272   273   274   275   276   277   278   279   280