Non-intersection ADT implementation file C Language

Source: Internet
Author: User

At first, we chose to use the ADT operation to allocate storage space. later I found that. in this way, there are so many problems that no analysis results will be produced after the analysis. simply go straight to the problem. My thoughts are good, I admit.

UpperCode.

/* Disjiontadt. C -- Non-intersecting set implementation file */<br/> # include <stdio. h> <br/> # include <stdlib. h> <br/> # include "disjiontadt. H "</P> <p>/* interface function definition */</P> <p> void initializeasheight (disjiontset gather, const int size) <br/>{< br/> int I; </P> <p> gather [0] = size; <br/> for (I = 1; I <= size; I ++) <br/> gather [I] = height; <br/>}</P> <p> void initializeassize (disjiontset gather, const int size) <br/>{< br/> int I; </P> <p> gather [0] = size; <br/> for (I = 1; I <= size; I ++) <br/> gather [I] = size; <br/>}</P> <p> int setunionasheight (disjiontset gather, settype root1, settype root2) <br/>{< br/> If (gather [root1]> 0 | gather [root2]> 0) <br/> return 0; <br/> If (gather [root2] <gather [root1]) <br/> gather [root1] = root2; <br/> else <br/> {<br/> If (gather [root1] = gather [root2]) <br/> gather [root1] --; <br/> gather [root2] = root1; <br/>}</P> <p> return 1; <br/>}</P> <p> int setunionassize (disjiontset gather, settype root1, settype root2) <br/> {<br/> If (gather [root1]> 0 | gather [root2]> 0) <br/> return 0; <br/> If (gather [root2] <gather [root1]) <br/> {<br/> gather [root2] + = gather [root1]; <br/> gather [root1] = root2; <br/>}< br/> else <br/> {<br/> gather [root1] + = gather [root2]; <br/> gather [root2] = root1; <br/>}</P> <p> return 1; <br/>}</P> <p> settype find (disjiontset gather, const item) <br/>{< br/> If (item> gather [0]) <br/> return OOS; <br/> else if (gather [item] <= 0) <br/> return item; <br/> else <br/> return gather [item] = find (gather, gather [item]); <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.