-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectionSort.java
More file actions
executable file
·71 lines (56 loc) · 1.21 KB
/
SelectionSort.java
File metadata and controls
executable file
·71 lines (56 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.util.*;
public class SelectionSort{
int[] list;
public SelectionSort(){
list = new int[5];
list[0]=5;
list[1]=6;
list[2]=2;
list[3]=9;
list[4]=1;
}
public void swap(int i,int j){
int temp;
temp=this.list[i];
this.list[i]=this.list[j];
this.list[j]=temp;
}
public void print(){
for (int el : this.list ) {
System.out.print(el+",");
}
System.out.println();
}
public void selectionSort(){
for(int i=0;i<this.list.length;i++)
{
for(int j=i+1;j<this.list.length;j++)
{
if(this.list[j]<this.list[i])
{
this.swap(i,j);
}
}
}
this.print();
}
public static void main(String[] arg){
// int n;
// System.out.print("Please enter the n");
// Scanner s= new Scanner(System.in);
// n=s.nextInt();
// System.out.print("input the values");
//
//
// ss.list[0]=Integer.parseInt(arg[0]);
// ss.list[1]=Integer.parseInt(arg[1]);
// ss.list[2]=Integer.parseInt(arg[2]);
// ss.list[3]=Integer.parseInt(arg[3]);
// // for(int i=0;i<n;i++)
// // {
// // ss.list[i]=s.nextInt();
// // }
SelectionSort ss=new SelectionSort();
ss.selectionSort();
}
}