-
Notifications
You must be signed in to change notification settings - Fork 181
/
Bubble Sort.java
executable file
·89 lines (37 loc) · 1.12 KB
/
Bubble Sort.java
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import java.util.Scanner; //Importing Scanner Library
public class Program
{
public static void main(String[] args) {
int [] sort = new int[10];
int i,j,k,u,v,m;
System.out.println("Enter 10 Numbers : ");
Scanner sc = new Scanner(System.in);
//For loop to accept the input
for(i = 0; i < (sort.length); i++)
{
sort[i] = sc.nextInt();
}
//Algorithm For Sorting
for(m = 0; m < 10; m++)
{
for(j = 0; j < (sort.length-1); j++)
{
/* Swap the values if first value is greater than the second */
if(sort[j] > sort[j+1])
{
v = sort[j];
u = sort[j+1];
sort[j] = u;
sort[j+1] = v;
}
else
continue;
}
}
//For loop for printing the sorted values
for(k = 0; k < sort.length; k++)
{
System.out.println(sort[k]);
}
}
}