Sort-heap Sort

Source: Internet
Author: User

Understanding understanding Understand Long live!!!

#include <cstdio> #include <cstring> #include <cstdlib> #define MAXSIZE 10typedef struct {int r[maxsize +1];int length;} Sqlist;void Swap (sqlist *l,int i,int j) {int temp = l->r[i]; L->r[i] = l->r[j]; L-&GT;R[J] = temp;} void Assignment (SqList *l,int len,int *a) {int i; L->length = Len;for (i=1;i<=len;i++) {l->r[i] = a[i-1];} return;} void Output (SqList L) {int i;for (i=1;i<=l.length;i++) {printf ("%d", L.r[i]);} printf ("\ n"); return;} Try to run your own code//See the "Big Talk Data Structure" 399 pages, must run all the way to understand the general meaning, void Heapadjust (SqList *l,int s,int m) {//Make L from S to M constitute Dagen int temp,j; temp = l->r[s];for (j=2*s;j<=m;j*=2) {//filter down on keywords with larger child nodes if (j<m && l->r[j]<l->r[j+1]) ++j;// J is the subscript if (Temp>=l->r[j]) break for the larger record in the keyword; L->r[s] = L->r[j];s = j;} L->r[s] = Temp;return;} void Heapsort (SqList *l) {int i;for (i=l->length/2;i>0;i--) {heapadjust (l,i,l->length);} for (i=l->length;i>1;i--) {Swap (l,1,i); Heapadjust (l,1,i-1);} return;} int main () {int a[10] = {9,1,5,8,3,7,4,6,2,10}; SqList L; Assignment (&l,10,a);  Heapsort (&l); Output (L); return 0;}


Sort-heap Sort

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: 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.