Computer Science, asked by Merry950, 10 months ago

Sort the following elements using Heap Sort: 10, 28, 46, 39, 15, 12, 18, 9, 56, 2

Answers

Answered by irakhedkar
1

//heap sort 1

class HeapSort{

public static void main(String args[]){

 int num[] = {10,28,46,39,15,12,18,9,56,2};

 int tempo;

 for(int i = 0; i < 10 - 1; i++){

  for(int j = i + 1; j < 10; j++){

   if(num[i]>num[j]){

    tempo = num[i];

    num[i] = num[j];

    num[j] = tempo;

   }

  }

 }

 for(int i = 0; i < 10; i++){

   System.out.println(num[i]);

  }

}

}

Hope this helps,

ira.

Similar questions