Selection Sort
Selection Sort
9 void accept()
10 {
11 Scanner scan = new Scanner(System.in);
12 System.out.println("Enter the size of the array");
13 int n = scan.nextInt();
14 a = new int[n];
15 System.out.println("Enter the values ");
16 for(int i=0;i<a.length;i++)
17 {
18 a[i] = scan.nextInt();
19 }
20 }
21
36 void selectionSort()
37 {
38 int i,j,t,len=a.length-1;
39 for(i=0;i<len;i++)
40 {
41 int k = lowest(i); // calling the function lowest by passing
starting index of the array.
42 if(a[k]<a[i])
43 {
44 t=a[i]; // swapping the value with lowest value
45 a[i]=a[k];
46 a[k]=t;
47 }
48 }
49 }
50
51 void display()
52 {
53 for(int i=0;i<a.length;i++)
54 {
55 System.out.println(a[i]);
56 }
57 }
58