forked from marktennyson/Java-programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsertionSorter.java
More file actions
35 lines (33 loc) · 795 Bytes
/
Copy pathInsertionSorter.java
File metadata and controls
35 lines (33 loc) · 795 Bytes
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
class ISorter{
int[] Arr;
int arrLen;
int i,j;
ISorter(int[] Arr){
this.Arr = Arr;
this.arrLen = this.Arr.length;
}
void sort(){
for (int i=1; i < this.arrLen; i++){
int key = this.Arr[i];
j = i-1;
while (j >= 0 && key < this.Arr[j]){
this.Arr[j+1] = this.Arr[j];
j = j-1;
}
this.Arr[j+1] = key;
}
}
void display(){
for (int k = 0; k < this.arrLen; k++) {
System.out.println(this.Arr[k]);
}
}
}
public class InsertionSorter {
public static void main(String[] args) {
int[] arr = {5,7,6,12,3};
ISorter sorter = new ISorter(arr);
sorter.sort();
sorter.display();
}
}