-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubble sort
More file actions
31 lines (31 loc) · 751 Bytes
/
Copy pathbubble sort
File metadata and controls
31 lines (31 loc) · 751 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
package Datastr;
//import java.util.Scanner;
public class Bubble_sort {
public static void main(String[] args) {
//Scanner sc = new Scanner(System.in);
int[] Array = {1,7,2,4,11,9,0};
System.out.println("Orignal array is ");
for(int i=0;i<Array.length;i++) {
System.out.print(Array[i]+" ");
}
System.out.println();
Bubble_sort obj = new Bubble_sort();
obj.sort(Array);
}
void sort(int[] Array) {
int temp=0;
for(int i=0;i<Array.length;i++) {
for(int j=0;j<Array.length-i-1;j++) {
if(Array[j]>Array[j+1]) {
temp = Array[j];
Array[j] = Array[j+1];
Array[j+1] = temp;
}
}
}
System.out.println("Sorted array is :");
for(int i=0;i<Array.length;i++) {
System.out.print(Array[i]+" ");
}
}
}