|
|
2鱼币
在火车上无聊在纸上写的 输出有误
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
typedef struct Nod
{
int num;
struct Nod * Next;
}NOD, *PNOD;
PNOD creat_list();
void show_list(PNOD pHead);
int main(void)
{
PNOD pHead = NULL;
pHead = creat_list();
show_list( pHead );
return 0;
}
PNOD creat_list()
{
PNOD P = NULL, pTail = NULL, pHead = NULL;
int len=3, i, val;
pHead = (PNOD)malloc(sizeof(NOD));
printf("Please enter the quantity of nodes: ");
scanf("%d", &len);
pTail = pHead;
pTail->Next = pHead;
for(i=0; i<len; i++)
{
P = (PNOD)malloc(sizeof(NOD));
printf("\n第%d个节点数据: ", i+1);
scanf("%d", &val);
P->num = val;
pTail->Next = P;
pTail = P;
P->Next = NULL;
}
printf("\n\n");
return pHead;
}
void show_list(PNOD pHead)
{
PNOD p = pHead->Next;
while ( p )
{
printf("%d ", &p->num);
p = p->Next;
}
}
|
|