-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathese4.java
33 lines (27 loc) · 1.11 KB
/
ese4.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
public class ese4 {
static int n = 30;
int arr[]=new int[n];
public static void main(String[] args) {
int arr={29,28,27,24,23,23,21,18,18,18,18,17,17,16,14,14,14,14,13,12,10,9,8,5,4,4,4,3,3,1};
}
static void bubbleSortAscending(int arr[][], int rowNumber) {
for (int i = 0; i < n - 1; i++)
for (int j = 0; j < n - i - 1; j++)
if (arr[rowNumber][j] > arr[rowNumber][j + 1]) {
// swap arr[j+1] and arr[j]
int temp = arr[rowNumber][j];
arr[rowNumber][j] = arr[rowNumber][j + 1];
arr[rowNumber][j + 1] = temp;
}
}
static void bubbleSortDescending(int arr[][], int rowNumber) {
for (int i = 0; i < n - 1; i++)
for (int j = 0; j < n - i - 1; j++)
if (arr[rowNumber][j] < arr[rowNumber][j + 1]) {
// swap arr[j+1] and arr[j]
int temp = arr[rowNumber][j];
arr[rowNumber][j] = arr[rowNumber][j + 1];
arr[rowNumber][j + 1] = temp;
}
}
}