diff --git a/src/ArrayBabble.java b/src/ArrayBabble.java index 2ed0030..2d5a392 100644 --- a/src/ArrayBabble.java +++ b/src/ArrayBabble.java @@ -1,8 +1,8 @@ -class ArrayBubble{ +class ArrayBabble{ private long[] a; //ссылка на массив private int elems; //количество элементов в массиве - public ArrayBubble(int max){ + public ArrayBabble(int max){ a = new long[max]; elems = 0; } @@ -15,8 +15,9 @@ class ArrayBubble{ public void printer(){ for (int i = 0; i < elems; i++){ System.out.print(a[i] + " "); - System.out.println(" "); + } + System.out.println(" "); System.out.println("---------------"); } @@ -27,8 +28,8 @@ class ArrayBubble{ } public void bubbleSorter(){ - for (int j = elems - 1; j >= 1; j--){ - for (int i = 0; i < j; i++){ + for (int j = 0; j a[i + 1]) toSwap(i, i + 1); } diff --git a/src/Main.java b/src/Main.java index 4bfaa5e..700cd80 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,23 +1,49 @@ +import java.lang.reflect.Array; +import java.util.Arrays; + public class Main { public static void main(String[] args) { - List ml = new List(); - ml.addFront(10,1993,"AAA","BBBB","CCC"); - ml.printList(); - ml.delFrontEl(); - ml.IsEmpty(); - ml.addFront(9,1993,"AAA","BBBB","CCC"); - ml.addBack(1,1990,"AAA","BBB","CCCC"); - ml.addBack(2,1991,"AAA","BXBB","CC"); - ml.addBack(3,1992,"AA","BBB","CiCi"); - - - ml.printList(); - System.out.println(); +// List ml = new List(); +// ml.addFront(10,1993,"AAA","BBBB","CCC"); +// ml.printList(); +//// ml.delFrontEl(); +//// ml.IsEmpty(); +//// ml.addFront(9,1993,"AAA","BBBB","CCC"); +//// ml.addBack(1,1990,"AAA","BBB","CCCC"); +//// ml.addBack(2,1991,"AAA","BXBB","CC"); +//// ml.addBack(3,1992,"AA","BBB","CiCi"); +// +//// +// ml.printList(); +// System.out.println(); + ArrayBabble Bubble = new ArrayBabble(10); + Bubble.into(2); + Bubble.into(4); + Bubble.into(8); + Bubble.into(7); + Bubble.into(6); + Bubble.into(0); + Bubble.into(2); + Bubble.into(5); + Bubble.into(9); + Bubble.into(11); + Bubble.printer(); + Bubble.bubbleSorter(); + Bubble.printer(); System.out.println(); + + +// int[] x = { 8, 0, 4, 7, 3, 7, 10, 12, -3,5 }; +// System.out.println(Arrays.toString(x)); +// int low = 0; +// int high = x.length - 1; +// +// QuickSort.QuickSort(x,low,high); +// System.out.println(Arrays.toString(x)); } } \ No newline at end of file diff --git a/src/QuickSort.java b/src/QuickSort.java new file mode 100644 index 0000000..579c350 --- /dev/null +++ b/src/QuickSort.java @@ -0,0 +1,43 @@ + +public class QuickSort { + + public static void QuickSort(int[] array, int low, int high) { + if (array.length == 0) + return; + + if (low >= high) + return; + + + int middle = low + (high - low) / 2; + int opora = array[middle]; + + + int i = low, j = high; + while (i <= j) { + while (array[i] < opora) { + i++; + } + + while (array[j] > opora) { + j--; + } + + if (i <= j) { + int temp = array[i]; + array[i] = array[j]; + array[j] = temp; + i++; + j--; + } + } + + + if (low < j) + QuickSort(array, low, j); + + if (high > i) + QuickSort(array, i, high); + } + +} \ No newline at end of file