C language for pairing heap merging routine in-situ queue

Source: Internet
Author: User

This is something I wrote yesterday. What I really appreciate is that the circular queue is implemented in the same place. It is very clear and has a good idea.

/* 12-34-11-04-05-19.32.c -- Chapter 12th, question 1 */<br/> # include "pairingheap. H "</P> <p> static node * combinesiblings_p (node * firstsibling) <br/>{< br/> static node * treearray [maxsiblings]; <br/> static node * First, * Second; <br/> int numsiblings; <br/> int front, rear; </P> <p>/* if only one tree, return it. */<br/> If (firstsibling-> nextsibling = nullnode) <br/> return firstsibling; <br/>/* place each sub Tree in treearray. */<br/> for (numsiblings = 0; firstsibling! = Nullnode; numsiblings ++) <br/>{< br/> treearray [numsiblings] = firstsibling; <br/>/* break links. */<br/> firstsibling-> previous-> nextsibling = nullnode; <br/> firstsibling = firstsibling-> nextsibling; <br/>}< br/>/* The COOD what appears later is so wonderful! */<Br/> front = rear = 0; <br/> DO <br/> {<br/> first = treearray [Front ++ % numsiblings]; <br/> second = treearray [Front ++ % numsiblings]; <br/> treearray [rear ++ % numsiblings] = compareandlink_p (first, second ); <br/>}< br/> while (front + 1) % numsiblings! = Rear % numsiblings) <br/>; </P> <p> return treearray [Front % numsiblings]; <br/>}

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.