forked from ghostmkg/programming-language
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubble_Sort.java
More file actions
Latest commit
26 lines (21 loc) · 585 Bytes
/
Copy pathBubble_Sort.java
File metadata and controls
26 lines (21 loc) · 585 Bytes
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
publicclassBubble_Sort{
publicstaticvoidprintArray(int[] arr){
for(inti=0;i<arr.length;i++){
System.out.print(arr[i]+" ");
}
}
publicstaticvoidmain(String[] args) {
intarr[]={7,8,3,2,1};
//bubble sort
for(inti=0;i<arr.length-1;i++){
for(intj=0;j<arr.length-1-i;j++){
if (arr[j]>arr[j+1]){
inttemp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
printArray(arr);
}
}