使用c语言单链表实现的一个集合,包含了交,差,并集运算

这篇博客介绍了如何使用C语言通过单链表来实现集合,并提供了交集、差集和并集的运算。文章包含set的头文件set.h、实现文件set.c以及测试主函数main.c的代码示例。
摘要由CSDN通过智能技术生成

下面是set的头文件源码,set.h

//
// Created by admin on 18/3/12.
//

#ifndef _SET_H
#define _SET_H

#include <stdio.h>

typedef enum BOOL { false, true } Boolean;

// Define the element of the set
typedef struct Item {
    int data;
    struct Item *link;
} SetItem;

// Define the struct set
typedef struct SET{
    SetItem *first;
    int size;
}Set;

// Returns true if there are currently *no* set objects in existence.
Boolean validateMemUse();

// Set constructor
Set * newSet();
//Set destructor
Set * deleteSet(Set * theSet);

// Insert an item into a set, noting that sets do not contain duplicate items.
// Returns true if the item was added to the set.
Boolean insertItem(Set * const theSet, const int newItem);
// Remove a given item, if it appears in the set.
// Returns true if the item was removed from the set.
Boolean removeItem(Set * const theSet, const int givenItem);

// Returns true if the two sets contain the same items.
Boolean equals(Set const * const setA, Set const * const setB);

// Return a new set that is the union of two sets (the two sets should be
// unchanged by the operation/Volumes/Disk4/NttDeve/C:C++Prac/2073-1226/set.h).
//
// The union of two sets A and B is defined to be another set
// containing all the items in A and all the items in B.
// (Note: Any item that is in BOTH A and B appears only once
// in the union, because no set contains duplicate items.)
// Example: If A = { 1, 2, 3 } and B = { 2, 4, 5, 6 }, then
// the union of A and B is the set { 1, 2, 3, 4, 5, 6 }.
Set * unionOf(Set const * const setA, Set const * const setB);

// Return a new set that is the intersection of two sets (the two sets should be
// unchanged by the operation).
//
// The intersection of two sets A and B is defined to be another set
// containing all the items in both A and B.
// Example: If A = { 1, 2, 3, 4 } and B = { 2, 3, 5 }, then
// the intersection of A and B is the set { 2, 3 }.
Set * intersectionOf(Set const * const setA, Set const * const setB);

// Return a new set that is the difference of two sets (the two sets should be
// unchanged by the operation).
//
// The difference (A\B) of two sets A and B is defined to be
// another set containing all the items in A that are NOT in B.
// Example: If A = { 1, 2, 3 } and B = { 2, 4, 5, 6 }, then
// the difference A\B of A and B is the set { 1, 3 }.
Set * differenceOf(Set const * const setA, Set const * const
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值