大白话讲数据结构和算法__番外 线性表的一些抽象数据类型

InitList(*L): 初始化操作,建立一个空的线性表L。


ListEmpty(L): 判断线性表是否为空表,若线性表为空,返回true,否则返回false。


ClearList(*L): 将线性表清空。


GetElem(L,i,*e): 将线性表L中的第i个位置元素值返回给e。


LocateElem(L,e): 在线性表L中查找与给定值e相等的元素,如果查找成功,返回该元素在表中序号表示成功;否则,返回0表示失败。


ListInsert(*L,i,e): 在线性表L中第i个位置插入新元素e。


ListDelete(*L,i,*e): 删除线性表L中第i个位置元素,并用e返回其值。


ListLength(L): 返回线性表L的元素个数。
 

这里举个例子:例如我们要实现这么一个程序,A=AUB,实现代码如下:

#include "stdio.h"
void union(List *La,list Lb)
{
    int la_len,ln_len;
    ElemType e;//定义任意数据类型e
    La_len=ListLength(*La);
    Lb_len=ListLength(Lb);
    for (int i=1;i<Lb_len;i++)
    {
        GetElem(Lb,i,&e);
        if (!LocateElem(*La,e))
        {
            ListInsert(La,++La_len,e);
        }
    }
}

猜你喜欢

转载自blog.csdn.net/qq_41686130/article/details/81409654