struct Node
{
int data;
struct Node * pNext;
};
struct Node *creat_list(void);
void traverse_list(struct Node *);
int main(viod)
{
struct Node * pHead = NULL;
pHead = creat_list();
traverse_list(pHead);
return 0;
}
struct Node * creat_list()
{
int i;
int val;
int length;
printf("请输入链表长度:");
scanf("d%",&length);
struct Node * pHead = (struct Node *)malloc(sizeof(struct Node)) ;
struct Node * pTail = pHead;
pTail->Next = NULL;//分配一个空头文件完成,尾部指向为空
for (i=0;i<length;++i)
{
printf("请输入第 d%节点",i+1);
scanf("d%",&val);
struct Node * pNew = (struct Node *)malloc(sizeof(struct Node));
if(pNew == NULL)
{ printf("分配失败,程序终止!");
exit(-1);
}
pNew->data = val;
pTail->data = pNew->data;
pTail->pNext =NULL;
}
traverse_list(pHead);
{
struct Node * p = pHead->pNext;
while (pNew == NULL)
{
printf("节点为 dd%",p->data);
p = p->pNext;
}
return;
}
}
1
comicfans44 2015-12-14 07:42:50 +08:00
struct Node * p = pHead->pNext;
while (pNew == NULL) -------------------------------> ??? { printf("节点为 dd%",p->data); p = p->pNext; } |