数据结构伪代码转换成可执行C++

有点急QwQ求求好人

第1个回答  2014-03-12
#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);
}本回答被提问者采纳
相似回答