ERROR;
q -> data = e;
q->next = p->next;
p->next = q;
return OK;
}
Status ListDelete_L(LinkList L, int i, Elemtype *e)
{
int j = 1;
LinkList q,p = NULL;
p = L->next;
if (p && j < i-1 )
{
p =p->next;
j++;
}
if (!p->next || j > i -1)
return ERROR;
q = p->next;
p->next = q->next;
*e = q->data;
free(q);
return OK;
}
void CreateList_L(LinkList L)
{
int i,j,e;
int len;
LinkList p,q;
q = L;
q->next = NULL;
printf("please input List len = ");
scanf("%d",&len);
/* 头插法
for (i = len; i > 0; --i)
{
j = len -i + 1;
p =(LinkList)malloc(sizeof(LNode));
if (!p)
exit (OVERFLOW);
printf("please input data for Link list %d: ", j);
scanf("%d", &e);
p->data = e;
p->next = L->next;
L->next =p;
} */
// 尾插法
for (i = len; i > 0; --i)
{
j = len -i + 1;
p =(LinkList)malloc(sizeof(struct LNode));
if (!p)
exit (OVERFLOW);
printf("please input data for Link list %d: ", j);
scanf("%d", &e);
p->data = e;
q->next = p;
p->next = NULL;
q = p;
}
}
void Print(LinkList L)
{
int i=1;
LinkList p = L->next;
while (p != NULL)
{
printf("\n##### No.%d value : %d ####",i,p->data);
p = p->next;
i++;
}
printf("\n");
}
void InvertLink(LinkList L)
{
LinkList s,p = NULL;
p = L->next;
L->next = NULL;
while (p != NULL)
{
s = p;
p = p->next;
s->next = L->next;
L->next = s;
}
}
int main(void)
{
int n,e,f;
Elemtype locat_e,current_e;
Elemtype *prior_e;
LinkList S;
S = InitList();
CreateList_L(S);
Print(S);
GetElem_L(S, 3, &e);
printf("e : %d\n",e);
Print(S);
//ListInsert_L(S, 3, 34);
//Print(S);
//ListDelete_L(S, 4, &f);
//Print(S);
//InvertLink(S);
//Print(S);
//ListEmpty(S);
//ClearList(S);
//Print(S);
f = ListLength(S);
printf("List length = %d \n",f);
//printf("please input located elem : e = ");
//scanf("%d",&locat_e);
//LocateElem(S,locat_e);
Print(S);
printf("please input node value : ");
scanf("%d",¤t_e);
PriorElem(S,current_e, &prior_e);
return 0;
}