Heap sequencing of data structures

Source: Internet
Author: User

PPT (original):

https://files.cnblogs.com/files/eastblue/heap sort. pptx

Video (original):

https://www.bilibili.com/video/av16199074/

Code:

#include <cstdio>#include<cstring>Const intmaxn=1e9+7;intb[50050];voidFunintA[],intI//a array I node completes the operation{    intL=sizeof(a), t;  while(2*i+1<l) {T=A[i]; if(2*i+2&LT;L)//There are two child nodes        {            if(a[2*i+1]<=a[2*i+2]&&a[2*i+1]<a[i])//swap with left child{A[i]=a[2*i+1]; a[2*i+1]=T; I=2*i+1; }            Else if(a[2*i+2]<a[2*i+1]&&a[2*i+2]<a[i])//swap with Right child{A[i]=a[2*i+2]; a[2*i+2]=T; I=2*i+2; }            Else                 Break; }        Else//only one child node        {                if(a[2*i+1]<A[i]) {A[i]=a[2*i+1]; a[2*i+1]=T; I=2*i+1; }             Else                 Break; }                }    }voidHeapsort (inta[]) {    intL=sizeof(a);  for(intI= (l2)/2; i>=0; i--)//array starting from 0, so ' filter ' from (L-2)/2 (second step for PPT){fun (a,i); }     for(intI=1; i<=l;i++)//(third step for PPT){b[i-1]=a[0]; a[0]=a[l-i]; A[l-i]=MAXN; Fun (A,0); }         for(intI=0; i<l;i++) A[i]=b[i];} intMain () {intarray[8]={ the, -, $, the, the, -, -, the};     Heapsort (array);  for(intI=0;i<8; i++) printf ("%d", Array[i]); }

Heap sequencing of data structures

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.