Page 583 - ComputerScience_Class_11
P. 583

Program 11    Design a class “Selection_Sort” that inputs an array from the user and sorts it in ascending
                                 order using  the selection  sort  technique.  A class  is  declared to  give the details  of the
                                 constructor and member methods.

                                 Data Members
                                 int ar[]                        :  Integer array to store array members
                                 int n                           :  To store the length of the array
                                 Member Methods
                                 Selection_Sort()                :  Constructor to initialise n to 0
                                 void readlist()                 :   To accept the value of n and array elements from the
                                                                   user
                                 int Index_Of_Min(int startindex)   :  To return the index position of the smallest value
                                 void sort()                     :   To sort the array in ascending  order  using  selection
                                                                   sort technique
                                  void display()                 :  To display the sorted array
                                 Write the main method to call the methods and run the program.

                   1       import java.util.*;

                   2       class Selection_Sort
                   3       {

                   4           int ar[],n;

                   5           Scanner sc=new Scanner(System.in);
                   6           Selection_Sort()

                   7           {

                   8               n=0;

                   9           }

                   10
                   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




                                                                                                Internal Assessment  581
   578   579   580   581   582   583   584   585   586   587   588