Repository navigation
Expand file tree
/
Copy pathMySort.java
More file actions
executable file
·76 lines (59 loc) · 1.57 KB
/
Copy pathMySort.java
File metadata and controls
executable file
·76 lines (59 loc) · 1.57 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
72
73
74
75
76
package javaConcepts.sortImp;
import java.util.ArrayList;
import java.util.List;
/**
* Created by asee2278 on 1/31/17.
*/
public class MySort {
public static void main(String[] args) {
List<Integer> a = new ArrayList<>();
a.add(348844);
a.add(99);
a.add(35);
a.add(32555);
a.add(32);
a.add(26444);
a.add(16);
a.add(16);
a.add(164444);
a.add(164444);
List<Integer> b = new ArrayList<Integer>();
b.add(32);
b.add(26444);
b.add(16);
b.add(16);
b.add(164444);
b.add(164444);
a =b;
Integer temp = 0;
System.out.println(a);
Integer count = 0;
for (int j=0;j <a.size() ; j++){
for (int i = 0; i < a.size()-j-1; i++) {
count++;
if (a.get(i) > a.get(i + 1)) {
temp = a.get(i);
a.set(i, a.get(i + 1));
a.set((i + 1), temp);
}
}
}
// for(int i = 0; i<a.size();i++){
//// System.out.println(a);
// for(int j = 1;j<a.size();j++){
// int temp;
// count++;
// if(a.get(j-1)>a.get(j)){
//
// temp = a.get(j);
// a.set(j, a.get(j-1));
// a.set(j-1, temp);
//
// }
// //System.out.println(a);
// }
// }
System.out.println(a);
System.out.print("total iteration"+count);
}
}