-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBubbleSort.java
More file actions
35 lines (30 loc) · 821 Bytes
/
BubbleSort.java
File metadata and controls
35 lines (30 loc) · 821 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
package Testing;
public class BubbleSort {
//Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order.
//Example:
public void buubleSort(int[] a)
{
int i, j, temp;
int n = a.length;
for(i=0; i <n;i++)
{
for(j=0; j< n-i-1;j++)
{
if(a[j] > a[j+1]) {
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
}
public static void main(String[] args) {
BubbleSort obj = new BubbleSort();
int[] a = {3,4,6,1,7,3,4,8,6,9};
obj.buubleSort(a);
for(int i=0; i <a.length; i++)
{
System.out.println(a[i]);
}
}
}