Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class a {
- static Scanner in = new Scanner(System.in);
- public static int n = in.nextInt();
- public static int a[] = new int[n + 2];
- public static int b[] = new int[n + 2];
- public static void main(String[] args){
- for (int i = 1; i < n + 1; i++)
- a[i] = in.nextInt();
- for (int i = n; i > 0; i--)
- b[i+1]=heap(i-1);
- for (int i = 2; i < n + 2; i++)
- System.out.print(b[i]+" ");
- }
- public static int heap(int q) {
- for (int i = n; i > q; i--)
- f(a, i);
- int temp=a[1];
- a[1]=0;
- return temp;
- }
- public static void f(int a[], int i) {
- while (i / 2 > 0) {
- if (a[i] > a[i / 2]) {
- int temp = a[i];
- a[i] = a[i / 2];
- a[i / 2] = temp;
- } else
- i /= 2;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement