#include <iostream>
#include <string>
#include <string.h>
using namespace std;
#define TRUE 1
#define OVERFLOW -2
#define MAXSIZE 100
#define OK 1
typedef int Status;
typedef int ElemType;
typedef struct{
ElemType *elem;
int length;
}SqList;
Status InitList_Sq(SqList *L)//初始化线性表
{
if(!L->elem) exit(OVERFLOW);
L->elem = new int [100];
L->length = 5;
return OK;
}
int IsEmpty(SqList * L)//判断线性表是否为空
{
if(L->length==0) return 1;
else return 0;
}
void DestroyList(SqList * L)
{
if(L->elem) free(L->elem);
}
void ClearList(SqList * L)
{
L->length = 0;
}
int main(){
SqList L;
L.elem = (ElemType*)malloc(sizeof(ElemType)*MAXSIZE);
InitList_Sq(&L);
printf("%d",L.length);
getchar();
for(int i = 0;i<10;i++)
{
L.elem[i] = i;
L.length++;
}
printf("%d\n",L.length);
int isempty = IsEmpty(&L);
printf("%d\n",isempty);
ClearList(&L);
isempty = IsEmpty(&L);
printf("%d\n",isempty);
getchar();
DestroyList(&L);
}
线性表的增删改查
最新推荐文章于 2023-04-16 17:44:10 发布