-
Notifications
You must be signed in to change notification settings - Fork 0
/
arr09.java
42 lines (33 loc) · 811 Bytes
/
arr09.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
//BUBBLE SORT(SORTING ALGORITHM)
package Array;
public class arr09 {
// programme for swapping elemrnt in array
public static void swapArr(int arr[] , int i , int j) {
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
public static void bubbleSort(int arr[]) {
int n = arr.length;
for(int i =0; i< n-1; i++) {
for(int j = 0; j< n -1 -i; j++ ) {
if(arr[j+1] < arr[j]) {
swapArr(arr, j+1, j);
}
}
}
}
//function for print Arr
public static void printArr(int arr[]) {
System.out.println("your required array =>");
for(int i=0; i< arr.length; i++) {
System.out.print(arr[i] +" ");
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int array[] = {4,7,1,9,2,5,3,6,8};
bubbleSort(array);
printArr(array);
}
}