我是靠谱客的博主 天真朋友,这篇文章主要介绍利用线性表中的顺序结构简单实现集合的交并补运算,现在分享给大家,希望可以做个参考。

//利用顺序表实现集合的运算
#include<cstdio>
#include<iostream>
#include<stdbool.h>
#define MAXSIZE 100//最大元素个数设置为100个
using namespace std;

typedef struct
{
   
    int *elem;
    int ListLength;
    int ListSize;
}SqList;
//分配内存
void malloc_space(SqList &L)
{
   
    L.elem=(int *)malloc(MAXSIZE*sizeof(int));
    L.ListLength=0;
    L.ListSize=100;
}
//将元素e插入到表中位置i处
bool Insert_elem(SqList &L,int i,int e)
{
   
    if(i<1||i>L.ListLength+1)//顺序表连续存储
        return false;
    if(i>L.ListSize)
        return false;
    int j;
    for(j=L.ListLength;j>=i;i--)
        L.elem[j]=L.elem[j-1];
    L.elem[i-1]=e;
    L.ListLength++;
    return true;
}
//删除表中位置i处的元素
bool Delet_elem(SqList &L,int i,int &e)
{
   
    if(i

最后

以上就是天真朋友最近收集整理的关于利用线性表中的顺序结构简单实现集合的交并补运算的全部内容,更多相关利用线性表中内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(110)

评论列表共有 0 条评论

立即
投稿
返回
顶部