Toggle navigation
Home
Latest pastes
FAQ
Random
BitBin is shutting down!
Register
Login
Bubble Sort Descending Order
SUBMITTED BY:
Guest
DATE:
Oct. 25, 2013, 9:31 p.m.
FORMAT:
Java
SIZE:
824 Bytes
Raw
Download
Tweet
HITS:
1030
Go to comments
Report
//Bubble Sort for Descending Order
public
static
void
BubbleSort
(
int
[
]
num
)
{
int
j
;
boolean
flag
=
true
;
// set flag to true to begin first pass
int
temp
;
//holding variable
while
(
flag
)
{
flag
=
false
;
//set flag to false awaiting a possible swap
for
(
j
=
0
;
j
<
num
.
length
-
1
;
j
++
)
{
if
(
num
[
j
]
<
num
[
j
+
1
]
)
// change to > for ascending sort
{
temp
=
num
[
j
]
;
//swap elements
num
[
j
]
=
num
[
j
+
1
]
;
num
[
j
+
1
]
=
temp
;
flag
=
true
;
//shows a swap occurred
}
}
}
}
Please enable JavaScript to view the
comments powered by Disqus.
comments powered by
Disqus