-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubble_Sort.java
More file actions
51 lines (38 loc) · 1.24 KB
/
Bubble_Sort.java
File metadata and controls
51 lines (38 loc) · 1.24 KB
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
45
46
47
48
49
50
51
import java.util.*;
class SortFunc{
void Sort(int arr[], int n){
for (int i=0; i<n-1; i++){
for (int j = 0; j < n-i-1; j++) {
if(arr[j]>arr[j+1]){
int temp = arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
System.out.println("After Bubble sorting the elements of the array are : ");
for(int i=0; i<n; i++){
System.out.println(arr[i]);
}
// return arr[n];
}
}
public class Bubble_Sort {
public static void main(String[] args){
System.out.println("Enter the size of the array : ");
Scanner sc1 = new Scanner(System.in);
int n = sc1.nextInt();
int arr[] = new int[n];
System.out.println("Enter the elements of the array :");
for(int i=0; i<n; i++){
arr[i] = sc1.nextInt();
}
System.out.println("Before sorting the elements of the array are :");
for(int i=0; i<n; i++){
System.out.println(arr[i]);
}
SortFunc obj = new SortFunc();
obj.Sort(arr, n);
// int arr1[n]; = obj.Sort(arr, n);
}
}