原理:利用大根堆或小根堆思想,首先建立堆,然后将堆首与堆尾交换,堆尾之后为有序区。

要点:建堆、交换、调整堆

实现:

Void HeapSort(Node L[])

{

BuildingHeap(L);//建堆(大根堆)

For(int i=n;i>0;i--)//交换

{

Int temp=L[i];

L[i]=L[0];

L[0]=temp;

Heapify(L,0,i);//调整堆

}

}

 

Void BuildingHeap(Node L[])

{ For(i=length/2 -1;i>0;i--)

Heapify(L,i,length);

}

排序算法的复杂度是o(n2) 终究是建立一个堆的排序算法 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-26
  • 2022-01-01
  • 2021-05-22
  • 2021-05-26
  • 2021-05-04
  • 2021-09-13
猜你喜欢
  • 2022-01-09
  • 2022-12-23
  • 2021-11-24
  • 2021-08-03
  • 2022-12-23
  • 2021-08-25
  • 2021-04-14
相关资源
相似解决方案