Skip to content

Commit 0935ee8

Browse files
authored
Add files via upload
1 parent f189d50 commit 0935ee8

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Bubble.java

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import java.util.*;
2+
3+
class Bubble {
4+
public static void main(String[] args) {
5+
int a[]= new int[1000];
6+
for(int i=0;i<1000;i++){
7+
a[i]=i;
8+
}
9+
long s= System.nanoTime();
10+
int swap =0;
11+
int comp=0;
12+
for (int i=0;i<999;i++)
13+
{
14+
15+
16+
for (int j=0;j<999;j++)
17+
{
18+
if(a[j]>a[j+1])
19+
{
20+
int temp=a[j];
21+
a[j]=a[j+1];
22+
a[j+1]=temp;
23+
swap++;
24+
}
25+
comp++;
26+
}
27+
}
28+
System.out.println("sorted array is:");
29+
long e = System.nanoTime();
30+
for(int i=0;i<1000;i++)
31+
{
32+
System.out.print(a[i]+",");
33+
}
34+
System.out.println("\ntotal time in nano secoend:"+(e-s));
35+
System.out.println("no of swap: "+swap);
36+
System.out.println("no of comparisons: "+comp);
37+
}
38+
}

0 commit comments

Comments
 (0)