数据结构日常打卡

it2022-05-05  103

线性表1

#define MaxSize 50 typedef int ElemType //声明线性表的顺序存储类型 typedef struct { Elemtype data[MaxSize]; int length; }SqList; //建立顺序表 void CreateList(SqList *&L,ElemType a[],int n) { int i=0,k=0; L = (SqList *)malloc(sizeof(SqList)); while(i<n){ L->data[k] = a[i]; k++;i++; } L->length = k; } //初始化线性表 void InitList(SqList *&L) { L - (SqList *)malloc(sizeof(SqList)); L ->length = 0; } //本算法的时间复杂度为O(1) //销毁线性表 void DestroyList(SqList *&L) { free(L); }//本算法的时间复杂度为O(1) //判断线性表是否为空 bool ListEmpty(SqList *L) { return(L->lenth==0); }//本算法的时间复杂度为O(1) //求线性表的长度 int ListLength(SqList *L) { return(L->length); }//本算法的时间复杂度为O(1) //输出线性表 void DispList(SqList *L) { for(int i=0;i<L->length;i++) printf("%d",L->data[i]); printf("\n"); }//本算法的时间复杂度为O(n)

最新回复(0)