Page 290 - Computer science 868 Class 12
P. 290

12                   minpos=i;
                13                   for (j =i+1; j < n; j++)

                14                   {
                15                       if (city[j].compareTo(min)<0)
                16                       {

                17                           min=city[j];

                18                           minpos=j;
                19                       }
                20                   }

                21                   temp = city[minpos];
                22                   city[minpos] = city[i];

                23                   city[i] = temp;
                24               }

                25           }
                26

                27           void printArray()
                28           {

                29               int n,i;
                30               n = city.length;

                31               for (i = 0; i < n; ++i)
                32                   System.out.print(city[i] + " ");

                33               System.out.println();
                34           }

                35
                36           public static void main(String args[])

                37           {
                38               SelectionSort ob = new SelectionSort();

                39               System.out.println("Before sorting array");
                40               ob.printArray();
                41               ob.selection();

                42               System.out.println("Sorted array");

                43               ob.printArray();
                44           }
                45       }





                288288  Touchpad Computer Science-XII
   285   286   287   288   289   290   291   292   293   294   295