链接: 王道2021数据结构链接 提取码:rpy8 –来自百度网盘超级会员V4的分享`
typedef int ElemType;
typedef int ElemType;
typedef struct LNode
{
ElemType data;
LNode* next;
}LNode,*LinkList;
void InitList(LinkList &L){
L = NULL;
}
int Length(LinkList L){
int length = 0;
p = L;
if(p == NULL){
length = 0;
}
while(p != NULL){
p = p->next;
length++;
}
return length;
}
bool Empty(LinkList L){
return L;
}
bool List_HeadInsert(LinkList &L){
InitList(L);
LNode * s;
int e;
scanf("%d", &x);
while(e != 9999){
s = (LNode *)malloc(sizeof(LNode));
s->data = e;
s->next = L->next;
L->next = s;
scanf("%d", &x);
}
return true;
}
bool List_TailInsert(LinkList &L){
InitList(L);
LNode *s, *r = L;
int e;
scanf("%d", &x);
while(e != 9999){
s = (LNode *)malloc(sizeof(LNode));
s->data = e;
s->next = r->next;
r->next = s;
r = s;
scanf("%d", &x);
}
s->next = NULL;
return true;
}
LNode* LocateElem_LNode(LinkList L, ElemType e){
if(L == NULL) return false;
LNode *p = L;
int j = 1;
while(p != NULL && p->data != e){
p = p->next;
j++;
}
return p;
}
ElemType GetElem(LinkList L, int i)
{
if(L == NULL || i < 1) return false;
LNode *p = L;
int j = 1;
while (p != NULL && j < i){
p = p->next;
j++;
}
return p;
}
|