forked from jvm-coder/Java_Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubbleSort.java
More file actions
35 lines (35 loc) · 852 Bytes
/
BubbleSort.java
File metadata and controls
35 lines (35 loc) · 852 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
29
30
31
32
33
34
35
import java.lang.*;
public class BubbleSort{
public static void main(String arg[])
{
int a[]={30,60,35,20,45,32,50};
System.out.println("Array Before Sorting");
for(int i=0;i<a.length;i++)
{
System.out.print(a[i]+" ");
}
System.out.println();
bubbleSort(a);
System.out.println("Array after sorting");
for(int i=0;i<a.length;i++)
{
System.out.print(a[i]+" ");
}
}
static void bubbleSort(int[] a){
int n = a.length;
int t = 0;
for(int i=0;i<n;i++)
{
for(int j=1;j<n-i;j++)
{
if(a[j-1]>a[j])
{
t = a[j-1];
a[j-1] = a[j];
a[j]= t;
}
}
}
}
}