Page 513 - Cs_withBlue_J_C11_Flipbook
P. 513

11          void read_list()          //initialising variables
                   12          {

                   13              System.out.println("ENTER THE SIZE OF THE ARRAY");
                   14              n=sc.nextInt();

                   15              ar=new int[n];
                   16              System.out.println("ENTER THE ARRAY ELEMENTS");

                   17              for(int i=0;i<n;i++)
                   18                  ar[i]=sc.nextInt();

                   19          }
                   20

                   21          int Index_Of_Min(int startindex) //finding index position of smallest element
                   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;




                                                                                                                       511
                                                                                                   Internal Assessment  511
   508   509   510   511   512   513   514   515   516   517   518