Page 584 - ComputerScience_Class_11
P. 584

22           {

                23               int p=startindex;
                24               for(int j=startindex+1;j<n;j++)

                25               {

                26                   if(ar[j]<ar[p])
                27                       p=j;

                28               }

                29               return p;

                30           }
                31

                32           void sort()

                33           {

                34               int i,x,t;
                35               for( i=0;i<n;i++) // swapping the variables

                36               {

                37                   x=Index_Of_Min(i);

                38                   t=ar[i]; ar[i]=ar[x]; ar[x]=t;
                39               }

                40           }

                41

                42           void display()
                43           {

                44               int i;

                45               System.out.println("THE SORTED ARRAY IS ");

                46               for(i=0;i<n;i++)
                47                   System.out.println(ar[i]);

                48           }

                49

                50           public static void main()
                51           {

                52               Selection_Sort ob=new Selection_Sort();





                  582  Touchpad Computer Science (Ver. 3.0)-XI
   579   580   581   582   583   584   585   586   587   588   589