#include<stdio.h>
#include<malloc.h>
#define MasSize 50
typedef char ElemType;
typedef struct
{
ElemType data[MasSize];
int lenth;
} SqList; //顺序类型定义
void InitList(SqList **L) //初始化顺序表
{
(*L) = (SqList *)malloc(sizeof(SqList));
(*L) -> lenth = 0;
}
void DestroyList(SqList *L) //释放顺序表
{
free(L);
}
int ListEmpty(SqList *L) //判断是否为空
{
return(L->lenth == 0);
}
int ListLength(SqList *L) //返回表的长度
{
return(L->lenth);
}
void DispList(SqList *L) //打印整个顺序表
{
int i;
if(ListEmpty(L)) return;
for (i = 0;i < L->lenth;i++)
printf("%c",L->data[i]);
printf("\n");
}
int GetElem(SqList *L,int i,ElemType *e) //拿到第i个元素并存到e所指向的变量中
{
if(i<1 || i>L->lenth)
return 0;
*e = L->data[i-1];
return 1;
}
int LocateElem(SqList *L,ElemType e) //查找元素e的位置
{
int i = 0;
while (i<L->lenth && L->data[i]!=e)
i++;
if (i>=L
顺序表的基本运算算法、指针与地址符
最新推荐文章于 2023-03-06 16:00:14 发布