-
Notifications
You must be signed in to change notification settings - Fork 47
/
bubbleSort.txt
44 lines (27 loc) · 952 Bytes
/
bubbleSort.txt
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
import java.util.Arrays;
//binary search in java
class Main{
static void bubbleSort(int array[]){
int size=array.length;
for (int step=0;step<size-1;++step){
for(int i=0;i<size-step-1;i++){
if(array[i]>array[i+1]){
int temp=array[i];
array[i]=array[i+1];
array[i+1]=temp;
}
}
}
}
static void printarray(int array[],int size){
for(int i=0;i<size;++i){
System.out.println(array[i]);
}
}
public static void main(String[] args){
int [] data={-2,45,8,11,-9};
Main.bubbleSort(data);
System.out.println("sorted array in ascending order:");
System.out.println(Arrays.toString(data));
}
}