package sort;
public class BobuleSort {
public static void bobule(int arr[]) {
for (int x = 0; x < arr.length; x++) {
for (int y = 0; y < arr.length - x - 1; y++) {
if (arr[y] > arr[y + 1]) {
int temp = arr[y];
arr[y] = arr[y + 1];
arr[y + 1] = temp;
}
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int arr[] = { 5, 8, 3, 9, 1, 2, 6 };
bobule(arr);
for (int x = 0; x < arr.length; x++) {
System.out.println(arr[x]);
}
}
}
package sort;
public class SelectSort {
public static void select(int[] arr) {
for (int x = 0; x < arr.length - 1; x++) {
for (int y = x + 1; y < arr.length; y++) {
if (arr[x] > arr[y]) {
int temp = arr[x];
arr[x] = arr[y];
arr[y] = temp;
}
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
int[] arr = { 2, 5, 3, 9, 5, 7 };
select(arr);
for (int x = 0; x < arr.length; x++) {
System.out.println(arr[x]);
}
}
}
|
|