This commit is contained in:
Garifullin-Farid 2024-05-20 19:26:45 +04:00
parent 00da6ce2f3
commit e967ef7b38
3 changed files with 88 additions and 18 deletions

View File

@ -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 <elems-1; j++){
for (int i = 0; i < elems-1-j; i++){
if(a[i] > a[i + 1])
toSwap(i, i + 1);
}

View File

@ -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));
}
}

43
src/QuickSort.java Normal file
View File

@ -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);
}
}