1个回答
展开全部
#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
#define LIST_INIT_SIZE 10
#define LISTINCREMENT 2
enum Status {OVERFLOW = 0, FALSE = 0, TRUE = 1, OK = 1};
typedef int ElemType;
typedef struct
{
ElemType *elem;
int length;
int listsize;
}SqList;
Status InitList(SqList *L)
{
(*L).elem = (ElemType*) malloc (LIST_INIT_SIZE * sizeof(ElemType));
if(!(*L).elem)
exit(OVERFLOW);
(*L).length = 0;
(*L).listsize = LIST_INIT_SIZE;
return OK;
}
Status DestroyList(SqList *L)
{
free((*L).elem);
(*L).elem = NULL;
(*L).length = 0;
(*L).listsize = 0;
return OK;
}
Status ClearList(SqList *L)
{
(*L).length = 0;
return OK;
}
Status ListEmpty(SqList L)
{
if(L.length == 0)
return TRUE;
else
return FALSE;
}
void main( )
{
SqList L;
InitList(&L);
printf("%d\n", L.length);
printf("%d\n", L.listsize);
if(ListEmpty(L)) printf("表空!\n");
else printf("表不空!\n");
DestroyList(&L);
}
#include <malloc.h>
#include <stdlib.h>
#define LIST_INIT_SIZE 10
#define LISTINCREMENT 2
enum Status {OVERFLOW = 0, FALSE = 0, TRUE = 1, OK = 1};
typedef int ElemType;
typedef struct
{
ElemType *elem;
int length;
int listsize;
}SqList;
Status InitList(SqList *L)
{
(*L).elem = (ElemType*) malloc (LIST_INIT_SIZE * sizeof(ElemType));
if(!(*L).elem)
exit(OVERFLOW);
(*L).length = 0;
(*L).listsize = LIST_INIT_SIZE;
return OK;
}
Status DestroyList(SqList *L)
{
free((*L).elem);
(*L).elem = NULL;
(*L).length = 0;
(*L).listsize = 0;
return OK;
}
Status ClearList(SqList *L)
{
(*L).length = 0;
return OK;
}
Status ListEmpty(SqList L)
{
if(L.length == 0)
return TRUE;
else
return FALSE;
}
void main( )
{
SqList L;
InitList(&L);
printf("%d\n", L.length);
printf("%d\n", L.listsize);
if(ListEmpty(L)) printf("表空!\n");
else printf("表不空!\n");
DestroyList(&L);
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |