package datastructure;import java.util.Arrays;
import java.util.Scanner;public class Sort {static int len; public static void main(String[] args) {Scanner sc = new Scanner(System.in);String str = sc.nextLine();String s[] = str.split(" ");int arr[] = new int[s.length];for (int i=0; i<s.length; i++) {arr[i] = Integer.parseInt(s[i]);}len = arr.length;System.out.println(Arrays.toString(arr));
heapSort(arr);System.out.println(Arrays.toString(arr));}public static int[] bubbleSort(int[] arr) {if (len == 0) {return arr;}for (int i=0; i<len-1; i++) {for (int j=0; j<len-1-i; j++) {if (arr[j] > arr[j+1]) {int temp = arr[j];arr[j] = arr[j+1];arr[j+1] = temp;}}}return arr;}public static int[] selectSort(int[] arr) {if (len == 0) {return arr;}for (int i=0; i<len; i++) {int minIndex = i;for (int j=i; j<len; j++) {if (arr[j] < arr[minIndex])minIndex = j;}int temp = arr[minIndex];arr[minIndex] = arr[i];arr[i] = temp;}return arr;}public static int[] insertSort(int[] arr) {if (len == 0) {return arr;}for (int i=0; i<len-1; i++) {for (int j=i+1; j>0; j--) {if (arr[j] < arr[j-1]) {int temp = arr[j];arr[j] = arr[j-1];arr[j-1] = temp;}}}return arr;}public static int[] shellSort(int[] arr) {if (len == 0) {return arr;}int temp, gap = len / 2;while (gap > 0) {for (int i=gap; i < len; i++) {temp = arr[i];int preIndex = i - gap;while (preIndex >= 0 && arr[preIndex] > temp) {arr[preIndex + gap] = arr[preIndex];preIndex -= gap;}arr[preIndex + gap] = temp;}gap /= 2;}return arr;}public static void quickSort(int[] arr, int L, int R) {if (L >= R) {return ;}int left = L;int right = R;int pivot = arr[left];while (left < right) {while (left<right && arr[right]>=pivot){right--;}arr[left] = arr[right];while (left<right && arr[left]<=pivot){left++;}arr[right] = arr[left];}arr[left] = pivot;quickSort(arr, L, right-1);quickSort(arr, right+1, R);}public static int[] heapSort(int[] arr) {if (len == 0) {return arr;}for (int i=len-1; i>0; i--) {buildMaxHeap(arr, i);int temp = arr[0];arr[0] = arr[i];arr[i] = temp;}return arr;}public static void buildMaxHeap(int[] arr, int n) {int child;for (int i=(n-1)/2; i>=0; i--) {child = 2 * i + 1;if (child !=n && arr[child] < arr[child+1]) {child++;}if (arr[i] < arr[child]) {int temp = arr[i];arr[i] = arr[child];arr[child] = temp;}}}
}