-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathBubbleSort.java
94 lines (83 loc) · 2.02 KB
/
BubbleSort.java
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
class BubbleSort{
public static void main(String[] a){
System.out.println(new BBS().Start(10));
Prover.answer(0);
}
}
// This class contains the array of integers and
// methods to initialize, print and sort the array
// using Bublesort
class BBS{
int[] number ;
int size ;
// Invoke the Initialization, Sort and Printing
// Methods
public int Start(int sz){
int aux01 ;
aux01 = this.Init(sz);
aux01 = this.Print();
System.out.println(65535);
aux01 = this.Sort();
aux01 = this.Print();
return 0 ;
}
// Sort array of integers using Bublesort method
public int Sort(){
int nt ;
int i ;
int aux02 ;
int aux04 ;
int aux05 ;
int aux06 ;
int aux07 ;
int j ;
int t ;
i = size - 1 ;
aux02 = 0 - 1 ;
while (aux02 < i) {
j = 1 ;
//aux03 = i+1 ;
while (j < (i+1)){
aux07 = j - 1 ;
aux04 = number[aux07] ;
aux05 = number[j] ;
if (aux05 < aux04) {
aux06 = j - 1 ;
t = number[aux06] ;
number[aux06] = number[j] ;
number[j] = t;
}
else nt = 0 ;
j = j + 1 ;
}
i = i - 1 ;
}
return 0 ;
}
// Printing method
public int Print(){
int j ;
j = 0 ;
while (j < (size)) {
System.out.println(number[j]);
j = j + 1 ;
}
return 0 ;
}
// Initialize array of integers
public int Init(int sz){
size = sz ;
number = new int[sz] ;
number[0] = 20 ;
number[1] = 7 ;
number[2] = 12 ;
number[3] = 18 ;
number[4] = 2 ;
number[5] = 11 ;
number[6] = 6 ;
number[7] = 9 ;
number[8] = 19 ;
number[9] = 5 ;
return 0 ;
}
}