-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubbleSort.java
More file actions
27 lines (23 loc) · 753 Bytes
/
Copy pathBubbleSort.java
File metadata and controls
27 lines (23 loc) · 753 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
import java.util.Arrays;
public class BubbleSort{
public static void bubbleSort(int[] arr){
int temp = 0;
for(int i = 0; i < arr.length; i++){
for(int j = 0; j < arr.length-1-i; j++){
if(arr[j] > arr[j+1]){
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}//end sort
public static void main(String[] args){
int[] arr = {3, 69, 45, 88, 24, 1, 5};
System.out.println("Original array: ");
System.out.println(Arrays.toString(arr));
bubbleSort(arr);
System.out.println("Sorted array: ");
System.out.print(Arrays.toString(arr));
}//end main
}