#include <stdio.h>
#include <malloc.h>
struct Node{
int data;
Node *next;
};
Node * createList(){
int len=0;
int iData=1;
Node *phead=(Node*)malloc(sizeof(Node));
if (NULL==phead)
{
printf("内存分配失败!\n");
return NULL;
}
Node * ptail=phead;
while(iData!=0)
{
printf("请输入第%d个元素 ",len);
scanf("%d",&iData);
Node* pnew=(Node*)malloc(sizeof(Node));
pnew->data=iData;
pnew->next=NULL;
ptail->next=pnew;
ptail=pnew;
++len;
}
return phead;
}
void showList(Node *phead){
phead=phead->next;
while(phead!=NULL){
printf("%d ",phead->data);
phead=phead->next;
}
}
int main()
{
Node* phead;
phead=createList();
showList(phead);
return 0;
}
list
最新推荐文章于 2024-06-02 22:35:45 发布