-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBubbleSort.java
39 lines (36 loc) · 1.22 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
/**
* BubbleSort class contains methods to sort various data structures in specific orders using the
* bubble sort algorithm.
*
*
*/
public class BubbleSort
{
public static Member[] bubbleSortA(Member[] teamMembers, boolean ascending)
{
int size = teamMembers.length;
int last, current;
Member temp;
for(last = size-1; last > 0; last = last - 1)
{ for(current = 0; current < last; current = current + 1)
{
if(ascending) {
if (teamMembers[current].getOld() > teamMembers[current + 1].getOld())
{
temp = teamMembers[current];
teamMembers[current] = teamMembers[current+1];
teamMembers[current+1] = temp;
}
} else {
if (teamMembers[current].getOld() < teamMembers[current + 1].getOld())
{
temp = teamMembers[current];
teamMembers[current] = teamMembers[current+1];
teamMembers[current+1] = temp;
}
}
}
}
return teamMembers;
}
}