为什么我的VC6.0运行不了这个数据结构的算法呢C语言的
#include <stdlib.h>#include <stdio.h>
#define OK 1
#define ERROR 0
#define TRUE 1
#define FALSE 0
typedef int ElemType;
typedef int Status;
typedef struct Node{
ElemType data;
struct Node* next;
}Node;
typedef struct Node* LinkList;
Status InitList(LinkList* L){
*L = (LinkList)malloc(sizeof(Node));
if(!(*L))
return ERROR;
(*L)->next = NULL;
return OK;
}
Status ListEmpty(LinkList L){
if(L->next)
return FALSE;
else
return TRUE;
}
int ListLength(LinkList L){
int i = 0;
LinkList p = L->next;
while(p){
i++;
p = p->next;
}
return i;
}
Status ListInsert(LinkList* L,int i,ElemType e){
int j ;
LinkList p,s;
p = *L;
j = 1;
while(p && j < i){
p = p->next;
++j;
if(!p || j > i)
return ERROR;
s = (LinkList)malloc(sizeof(Node));
s->data = e;
s->next = p->next;
p->next = s;
return OK;
}
Status visit(ElemType c){
printf("%d",c);
return OK;
}
Status ListTraverse(LinkList L){
LinkList P = L->next;
while(p){
visit(p->data);
p = p->next;
}
printf("\n");
return OK;
}
Status ClearList(LinkList* L){
LinkList p,q;
p = (*L)->next;
while(p){
q = p->next;
free(p);
p = q;
}
(*L)->next = NULL;
return OK;
}
int main(int argc,char* argv[]){
Status i = 0;
int j,k;
LinkList L;
i = InitList(&L);
if(ListEmpty(L) == TRUE)
printf("链表初始化成功\n");
else
printf("链表初始化失败\n");
printf("链表的长度为:%d\n",ListLength(L));
for(j = 0; j < 5; j++)
i = ListInsert(&L,1,j);
printf("在L的表头依次插入1-5后:L.data=");
i = ClearList(&L);
printf("清空后表长为:%d\n",ListLength(L));
printf("L是否为空:%d(1:是,0:否)\n",ListEmpty(L));
for(j = 0; j < 10; j++)
i = ListInsert(&L,j,j);
printf("在L的表尾依次插入1-10后:L.data=");
ListTraverse(L);
printf("ListLength(L) = %d\n",ListLength(L));
return 0;
}
你的编译器没有报错吗?
你为什么不看编译器给出的提示?
Status ListInsert(LinkList* L,int i,ElemType e){
int j ;
LinkList p,s;
p = *L;
j = 1;
while(p && j < i){
p = p->next;
++j;
if(!p || j > i)
return ERROR;
s = (LinkList)malloc(sizeof(Node));
s->data = e;
s->next = p->next;
p->next = s;
return OK;
}
Status ListInsert(LinkList* L,int i,ElemType e){
int j ;
LinkList p,s;
p = *L;
j = 1;
while(p && j < i){
p = p->next;
++j;
if(!p || j > i)
return ERROR;
s = (LinkList)malloc(sizeof(Node));
s->data = e;
s->next = p->next;
p->next = s;
return OK;
}
}
Status ListTraverse(LinkList L){
LinkList P = L->next;
while(p){
visit(p->data);
p = p->next;
}
printf("\n");
return OK;
}
while(p)
main.c: In function ‘main’:
main.c:98:11: warning: unused variable ‘k’ [-Wunused-variable]
98 | int j,k;
| ^
main.c:97:12: warning: variable ‘i’ set but not used [-Wunused-but-set-variable]
97 | Status i = 0;
| ^
main.c: In function ‘ListInsert’:
main.c:63:1: warning: control reaches end of non-void function [-Wreturn-type]
63 | }
| ^
人造人 发表于 2021-5-22 09:58
你的编译器没有报错吗?
你为什么不看编译器给出的提示?
有一个错误。但是我看不懂哪里错了呀
页:
[1]