【C++学习】实现一个静态链表

#include
#include 
using namespace std;

#define MAXSIZE 100 
int data[MAXSIZE];
typedef int ElemType; // 给数组元素的数据类型起个别名

size_t length;

struct SeqList{
    ElemType data[MAXSIZE];
    size_t length;
};
// 清空顺序表
void ClearList(SeqList &LL){
    LL.length = 0;// 表长设置
    memset(LL.data,0,sizeof(ElemType)*MAXSIZE); // 清空数组
}
bool InsertList(SeqList& LL, const size_t pos, const ElemType& ee){
    if(LL.length == MAXSIZE){
        cout << "顺序表已满,不能插入。\n";return false;
    }
    // 判断位置pos是否合法。
    if(pos<1||pos > LL.length + 1){
        cout << "插入位置" << pos << "不合法,应该在1-"< LL.length + 1){
        cout << "插入位置" << pos << "不合法,应该在1-"<0元素ee在表LL中的位置。
size_t FindElem(const SeqList& LL,const ElemType& ee){
    for (size_t i = 0; i < LL.length; i++)
    {
        if(LL.data[i]==ee) return i+1;
    }
    return 0;
}
// 删除顺序表LL中的第pos个元素,返回值:0-位置pos不合法;1-成功。
bool DeleteElem(SeqList &LL, const size_t pos){
    // 判断位置pos是否合法。
    if(pos<1||pos > LL.length + 1){
        cout << "删除位置" << pos << "不合法,应该在1-"<

你可能感兴趣的:(C++,c++)