Data Structure practice-sequence table: intersection of two sets and intersection of data structures

Source: Internet
Author: User

Data Structure practice-sequence table: intersection of two sets and intersection of data structures

[Project-calculate the union of sets]
Assume that two sets A and B are represented by two linear tables LA AND LB respectively, that is, the data element in the linear table is A member in the set. Design the algorithm. Use the unionList (List LA, List LB, List & LC) function to implement the algorithm and obtain A new set C = A ∪ B, place the union of the two sets in the linear table LC.

Tip:
(1) In addition to implementing the unnionList function, you also need to design code in the main function and call unionList for testing and demonstration;
(2) Make full use of the previously created Algorithm Library [Click…], Add directly in the program Header#include<list.h>(The most common method in the project, recommended );
(3) You can also store the functions corresponding to the basic operations of linear tables required by the algorithm in the same file as all programs you have designed.

[Reference]

# Include "list. h "# include <stdio. h> void unionList (SqList * LA, SqList * LB, SqList * & LC) {int lena, I; ElemType e; InitList (LC); for (I = 1; I <= ListLength (LA); I ++) // insert all the elements of LA into Lc {GetElem (LA, I, e); ListInsert (LC, I, e);} lena = ListLength (LA); // obtain the length of the linear LA table for (I = 1; I <= ListLength (LB); I ++) {GetElem (LB, I, e); // obtain the I-th Data Element in LB and assign it to e if (! LocateElem (LA, e) // The LA does not have the same person as e, and is inserted into the LC ListInsert (LC, ++ lena, e );}} // use main to write the test code int main () {SqList * sq_a, * sq_ B, * sq_c; ElemType a [6] = {5, 8, 7, 2, 4, 9}; CreateList (sq_a, a, 6); printf ("LA:"); DispList (sq_a); ElemType B [6] = {2, 3, 8, 6, 0}; CreateList (sq_ B, B, 5); printf ("LB:"); DispList (sq_ B); unionList (sq_a, sq_ B, sq_c); printf ("LC:"); DispList (sq_c ); return 0 ;}

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.