-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubble_sort.java
More file actions
28 lines (28 loc) · 803 Bytes
/
Bubble_sort.java
File metadata and controls
28 lines (28 loc) · 803 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
27
28
public class Bubble_sort {
public static void main(String[] args) {
int nums[] = {6,5,2,8,9,4};
int size=nums.length;
int temp=0;
System.out.println("Before sorting");
for (int num:nums){
System.out.print(num+" ");
}
for (int i=0;i<size;i++){
for (int j=0;j<size-1;j++){
if (nums[j]>nums[j+1]){
temp=nums[j];
nums[j]=nums[j+1];
nums[j+1]=temp;
}
}
System.out.println();
for (int num:nums){
System.out.print(num+" ");
}
}
System.out.println("\nAfter sorting");
for (int num:nums){
System.out.print(num+" ");
}
}
}