Small heap of clues two fork tree supplement

Source: Internet
Author: User

1, small heap:

Heap Construction,i> array directly generated heap (downward adjustment),iii> insert create heap (upward adjustment);

(1), how to achieve an adjustment?

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M02/85/9C/wKiom1ep68rybjPNAAAnLBKGn-0983.png-wh_500x0-wm_3 -wmp_4-s_2320125656.png "title=" Qq20160809224147.png "alt=" Wkiom1ep68rybjpnaaanlbkgn-0983.png-wh_50 "/>

Find the last non-leaf knot, n/2-1; Keep adjusting!

(2) Heap Row-----> Priority queue

heap deletion, only the top element of the heap, and then the last element to add up. Make an adjustment down. To form a new heap structure (which satisfies the nature of the heap), the deleted digital output is the heap row.

Small heap: The root (parent) is less than the left and right nodes, the smallest number first out;

Large heap: The root (parent) is greater than the left and right nodes, the largest number is first out, so the heap is the priority queue!

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/85/9C/wKioL1ep73eDVVsSAAAY1GUgloc269.png-wh_500x0-wm_3 -wmp_4-s_638504117.png "title=" Qq20160809225730.png "alt=" Wkiol1ep73edvvssaaay1gugloc269.png-wh_50 "/>

2, clue two tree Search parent Node graph interpretation

Use the null pointer to point to the precursor, the successor node.

650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M00/85/9C/wKiom1ep9Z6zQy9WAABRj50VdzA198.png-wh_500x0-wm_3 -wmp_4-s_2805794028.png "title=" Qq20160809232339.png "alt=" Wkiom1ep9z6zqy9waabrj50vdza198.png-wh_50 "/>

3, programming when the Const some attention

(1), in C + +, when we pass a constant, when the reference is received, the formal parameter must be accepted by the const type, otherwise an error occurs!

Constants must be frequently referenced for acceptance.

Example: int find (+); int find (const int &value);

(2), typedef void *IP;

const IP m; How to understand?

Because IP is a data type, const and data types can be swapped for locations,

const IP m;  <==> IP const m; i.e. void *const m; M is a pointer to the spatial data that cannot be changed, which points to can be changed!!!


Small heap of clues two fork tree supplement

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.