-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathselection-sort.java
More file actions
50 lines (42 loc) · 1.12 KB
/
selection-sort.java
File metadata and controls
50 lines (42 loc) · 1.12 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
class Selection
{
int minIndex(int Array[] , int start, int end)
{
int minIndex = start;
for (int i = start+1; i < end; i++)
{
if ( Array[i] < Array[minIndex] )
{
minIndex = i;
}
}
return minIndex;
}
int[] sorting(int Array[],int length)
{
for (int i = 0; i < length-1; i++)
{
int minI = minIndex(Array, i, length);
int temp = Array[minI];
Array[minI] = Array[i];
Array[i] = temp;
}
return Array;
}
}
/**
* SelectionSort
*/
public class SelectionSort {
public static void main(String[] args) {
int Array[] = {1,2,3,4,5,6,7,8,9};
Selection s1 = new Selection();
long startTime = System.nanoTime();
int sortedArray[] = s1.sorting(Array, 9);
long endTime = System.nanoTime();
for (int i = 0; i < 9; i++) {
System.out.println(sortedArray[i]);
}
System.out.println("Total Time in Neno Second: "+ (endTime-startTime));
}
}