package
liaojiyong.net.blogjava;
/**
*
@author
liaojy
*
*/
public
class
BubbleSort {
static
int
[]
arr
= { 1, 2, 6, 3, 11, 92, 12, 5 };
/**
*
@param
args
*/
public
static
void
main(String[] args) {
//
TODO
Auto-generated method stub
System.
out
.println(
"Before Sort..."
);
for
(
int
temp1 :
arr
) {
System.
out
.print(temp1 +
" "
);
}
System.
out
.println();
sort(
arr
);
System.
out
.println(
"After Sort..."
);
for
(
int
temp2 :
arr
) {
System.
out
.print(temp2 +
" "
);
}
System.
out
.println();
}
public
static
void
sort(
int
[] a) {
for
(
int
i = 0; i < a.
length
; i++) {
for
(
int
j = i + 1; j < a.
length
; j++) {
if
(a[i] > a[j]) {
a[i] = a[i] + a[j];
a[j] = a[i] - a[j];
a[i] = a[i] - a[j];
}
}
}
}
}
Before Sort...
1 2 6 3 11 92 12 5
After Sort...
1 2 3 5 6 11 12 92