-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubble_Sorting.java
More file actions
54 lines (46 loc) · 1.45 KB
/
Bubble_Sorting.java
File metadata and controls
54 lines (46 loc) · 1.45 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
52
53
54
// Bubble Sort Program
package bubble_sorting;
public class Bubble_Sorting {
// This function is Bubble Sort
public static void Bubble_Sorting (int [] Array)
{
int x;
for (int i = 0; i < Array.length -2; i++)
{
System.out.println("Pass : " +(i+1));
for (int j = 0; j < Array.length - 1; j++)
{
if (Array[j] > Array[j + 1])
{
x = Array[j];
Array[j] = Array[j + 1];
Array[j + 1] = x;
// This statment print the array
Display(Array);
}
}
System.out.println("");
}
}
// this is display function
public static void Display(int [] array)
{
for (int i = 0; i < array.length; i++)
{
System.out.print(array[i] + " ");
}
System.out.println();
}
public static void main(String[] args) {
int [] array = {5,17,8,9,3,6,1,13};
// before sortin of array
System.out.print("Before Sorting Array : ");
Display(array);
System.out.println("");
// Calling sort function
Bubble_Sorting(array);
// Printing array after sorting
System.out.print("After Sorting Array : ");
Display(array);
}
}