I read introduction to algorithms in C Language (3) -- heap sorting and priority queue

Source: Internet
Author: User

heap sorting is an algorithm with excellent performance. generally, the sorting effect is achieved through the data structure-Max heap, the general steps are: heap building-sorting, heap building and sorting are mixed to maintain the stability of the heap. Priority Queues also use data structure heaps. The main C language algorithms are as follows:

# Include <stdio. h> # include <limits. h> // record the maximum heap length unsigned int heap_size = 0; // The subscript starts from 0. // find the subscript unsigned int parent (unsigned int index) of the parent node) {return (index-1)/2;} // evaluate the subscript unsigned int lchild (unsigned int index) of the Left son node {return 2 * index + 1 ;} // calculate the subscript unsigned int rchild (unsigned int index) {return 2 * index + 2;} // maintain the maximum heap order void max_heapify (int *, unsigned int I) {unsigned int L, R, largest; inttemp; Largest = I; L = Lchild (I); r = rchild (I); If (L 

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.