typedef enum{ERROR, OK} status;
typedef enum{FALSE, TRUE} boolean;
typedef int ElemType;
typedef struct LNode {
ElemType data; //数据域
struct LNode *next;//指针域
} LNode, *LinkList;//LinkList为Lnode类型的指针
status InitList(LinkList L);
boolean isEmpty(LinkList L);
status GetElem(LinkList L, int i, ElemType *e);
status InitList(LinkList L) {
L = (LinkList)malloc(sizeof(LNode));
if(L == NULL)
return ERROR;
L->data = 0;
L->next = NULL;
}
boolean isEmpty(LinkList L) {
if(L->data == 0)
return TRUE;
else
return FALSE;
}
status GetElem(LinkList L, int i, ElemType *e) {
LNode *p;
int pos;
if(i < 1 || i > L->data)
return ERROR;
p = L->next;
for( pos = 1; pos < i; pos++)
p = p->next;
e = p->data;
return OK;
}
LNode FindElem(LinkList L, ElemType *e){
LNode *p;
for(p = L->next; p != NULL; p = p -> next)
if(p -> data == *e)
break;
return p;
}