Page 577 - Computer science 868 Class 12
P. 577

13      ar=new int[n];  // declare array
                   14      System.out.print("Enter the element of the array:");

                   15      for(int i=0;i<n;i++)   // input
                   16      {
                   17      ar[i]=sc.nextInt();

                   18          }

                   19      }
                   20      void sort()
                   21      {

                   22      int h,i,hp=0,nh,nhp=0,temp;
                   23      if(n%2==0)

                   24      {
                   25      mid=(n-1)/2;

                   26      }
                   27      else

                   28      {
                   29      mid=n/2;

                   30      }
                   31      left=mid-1;

                   32      right=mid+1;
                   33      h=ar[0];

                   34      for(i=1;i<n;i++)  // finding highest
                   35      {

                   36      if(ar[i]>h)
                   37      {

                   38      h=ar[i];
                   39      hp=i;

                   40          }
                   41      }
                   42      temp=ar[hp];  //swapping numbers in middle and highest position

                   43      ar[hp]=ar[mid];

                   44      ar[mid]=temp;
                   45      count=2;







                                                                                                                       575
                                                                                                   Internal Assessment  575
   572   573   574   575   576   577   578   579   580   581   582