#include
#include
#include
typedef struct Node
{
int data;//数据域
struct Node* pNext;//指针域
}NODE,*PNODE;
PNODE creat_list(void);
void traverse_list(PNODE pHead);
bool is_empty(PNODE pHead);
int length_list(PNODE);
bool insert_list(PNODE,int ,int);
bool delete_list(PNODE,int,int*);
void sort_list(PNODE);
PNODE creat_list(void)
{
int len;
int i;
int val;
PNODE pHead =(PNODE)malloc(sizeof(NODE));
if(pHead==NULL)
{
printf("分配失败,程序终止!\n");
exit(-1);
}
PNODE pTail =pHead;
pTail->pNext = NULL;
printf("请输入您要生成的链表的节点的个数:len= ");
scanf("%d",&len);
for(i=0;i
printf("请输入第%d个节点的值:",i+1);
scanf("%d",&val);
PNODE pNew =(PNODE)malloc(sizeof(NODE));
if(pNew==NULL)
{
printf("分配失败,程序终止!\n");
exit(-1);
}
pNew->data =val;
pTail->pNext =pNew;
pNew->pNext =NULL;
pTail = pNew;
}
return pHead;
}
void traverse_list(PNODE pHead)
{
PNODE p=pHead->pNext;
while(NULL!= p)
{
printf("%d ",p->data);
p=p->pNext;
}
printf("\n");
return ;
}
bool is_empty(PNODE pHead)
{
if(NULL == pHead->pNext)
return true;
else
return false;
}
int length_list(PNODE pHead) //改动地方
{
PNODE p;
p = pHead->pNext;
int len =0;
while (NULL!=p)
{
++len;
p=p->pNext;
}
return len;
}
void main( ) //改动地方
{
PNODE pHead =NULL;
pHead=creat_list();
traverse_list(pHead);
int len = length_list(pHead);
printf("链表的长度是%d\n",len);
}
抄的不错
.....
}
int length_list(PNODE); // <<<有没有发现啊,多一个分号!!! 去掉分号就好啦,不去就语法错
{
.....
那函数的后面的“;”用来做什么的呢,没用去掉吧