Page 576 - Computer science 868 Class 12
P. 576

Output of the preceding program is as follows:

              ENTER SIZE OF ARRAY
              3
              ENTER ARRAY ELEMENTS

              999
              100
              555

              THE SORTED IS :
              100 555 999




                Program 4      Design a class Mid_Sort to sort a given a array using Mid Sort Technique keeping the highest
                               number in the middle and then the second highest to the right and third highest to the
                               left and so on. A main class is declared to give details of the constructor and the member
                               methods.
                               Data Members
                               int right, left, mid         :  to store array position.
                               int count                    :  acts as a counter variable
                               int n                        :  to store the array size

                               int a[]                      :  integer array to perform
                               Member Function
                               Mid_Sort()                   :  constructor that initialised member data to zero
                               void input(int)              :  accepts data from the user

                               void sort()                  :   sort the given array according to the technique mentioned
                                                               above
                               void display()               :  to display the array before and after sorting

                 1       import java.util.*;
                 2       class Mid_Sort

                 3       {
                 4       int  right,left,mid,n,count, ar[]; //member data

                 5       Scanner sc= new Scanner(System.in);
                 6       Mid_Sort()   // default constructor
                 7       {

                 8       right=left=mid=n=count=0;

                 9       }
                10       void input(int x)
                11       {

                12       n=x;




                574574  Touchpad Computer Science-XII
   571   572   573   574   575   576   577   578   579   580   581