public int[] BubbleSort(int[] input) {
int size=input.length;
for(int i=0; i<size; i++) {
boolean flag = true;
int s=size-i-1;
for(int j=0; j<s; j++) {
if(input[j]>=input[j+1]) {
flag=false;
input[j] = input[j]+input[j+1];
input[j+1] = input[j]-input[j+1];
input[j] = input[j]-input[j+1];
}
}
if(flag) break;
}
return input;
}
No comments:
Post a Comment