-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBubbleSort.java
More file actions
49 lines (40 loc) · 1.08 KB
/
BubbleSort.java
File metadata and controls
49 lines (40 loc) · 1.08 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
import java.util.Scanner;
public class BubbleSort {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n;
System.out.println("Enter an array size");
n = sc.nextInt();
System.out.println("Enter " + n + " Element in array");
int []arr = new int[n];
// for(int i:arr)
for(int i=0;i<arr.length;i++)
{
arr[i] = sc.nextInt();
}
System.out.println("Before using Bubble Sort");
for(int i:arr)
{
System.out.println(i);
}
for(int j=0;j>arr.length;j++)
{
for(int i=arr.length-1;i>=0;i--)
{
if(arr[i]<arr[i-1])
{
int temp;
temp = arr[i];
arr[i] = arr[i-1];
arr[i-1] = arr[i];
}
}
}
System.out.println("After using Bubble Sort");
for(int i:arr)
{
System.out.println(i);
}
sc.close();
}
}