数据结构中的错误,帮我改改
#include "stdafx.h"#include<stdlib.h>
typedef int ElemType;
/ pedef POINT ElemType;
/ pedef double ElemType;
/ pedef char ElemType;
#define ERROR 0
#define OK 1
typedef struct node
{
ElemType elem;
struct node*next;
}NODE;
typedef struct
{
NODE*head;
}LINK_LIST;
int IntList(LINK_LIST*L)
{
L->head=(NODE*)malloc(sizeof(NODE));
if(L->head){L->head->next=NULL;return OK;}
return ERROR;
}
void Destorylist(LINK_LIST*L)
{
NODE*p;
while(L->head)
{
p=L->head;
L->head=L->head->next;
free(p);
};
}
void ClearList(LINK_LIST*L)
{
NODE*p;
while(L->head->next)
{
p=L->head->next;
L->head->next=p->next;
free(p);
}
int ListLength(LINK_LIST L)
{
NODE*p;
int len;
for(p=L.head,len=0;p->next!NULL;p->next,len++);
return(len);
}
int IsEmpty(LINK_LIST L)
{
return(L->head->next==NULL);
}
bool GetElem(LINK_LIST L,int i,ElemType*e)
{
NODE*p;
int j;
if(i<1||i>ListLength(L))return ERROR;
for(p=L.head,j=0;j!=i;p->next,j++);
*e=p->elem;
return OK;
}
NODE*LocateElem(LINK_LIST L,ElemType e)
{
NODE*p;
for(p=L.head->next;p&&p->elem!=e;p=p->next);
return(p);
}
NODE*PriorElem(LINK_LIST L,NODE*e)
{
NODE*p;
if(L.head->next==e)return NULL;
for(p=L.head;p->next&&p->next!=e;p=p->next);
if(p->next==NULL)return NULL;
if(p->next==e)return p;
return NULL;
}
NODE*NextElem(LINK_LIST L,NODE*e)
{
NODE*p;
for(p=L.head->next;p&&p!=e;p=p->next);
if(p)p=p->next;
return p;
}
int ListInsert(LINK_LIST*L,int i,ElemType e)
{
NODE*p,*s;
int j;
if(i<1||ListLengh(*L)+1) return ERROR;
s->elem=e;
for(p=L->head,j=0;p&&j<i-1;p=p->next,j++);
s->next=p->next;
p->next=s;
return OK;
}
int ListDelete(LINK_LIST*L,int i,ElemType*e)
{
NODE*p,*s;
int j;
if(i<||i>ListLengh(*L)) return ERROR;
for(p=L->head,j=0;j<i-1;p=p->next,j++);
s=p->next;
*e=s->elem;
p->next=s->next;
free(s);
return OK;
}
int main(int argc, char* argv[])
{
//printf("Hello World!\n");
LINK_LIST L1,L2;
int i;
InitList(&L1);
InitList(&L2);
for(i=0;i<25;i++)
{
ListInsert(&L1,i,i);
ListInsert(&L2,i,25-i);
};
ElemType e,e1,e2;
i=10;
GetElem(L1,i,&e1);
if(!GetElem(L2,i,&e2))
printf("error in GetElem (L2)!\n");
else printf("e1=%de2=%d\n",e1,e2);
ListDelete(&L1,5,&e1)
ListInsert(&L2,7,e2)
printf("e1=%de2=%d\n",e1,e2);
DestroyList(&L1);
DestroyList(&L2);
return 0;
}