C创建链表(二)

来源:互联网 发布:数据安全存储方案 编辑:程序博客网 时间:2024/06/03 12:41

#include <stdio.h>
#include <stdlib.h>

typedef struct Node{
    int data;
    struct Node *next;
}No;

int main()
{
    No *head;      //头指针
    head=(No*)malloc(sizeof(No));
    No *p=head;
    int e,i;
    for(i=0;i<9999;i++)
    {
        scanf("%d",&e);
        if(e)
        {
           head->data=e;
           head->next=(No*)malloc(sizeof(No));
           head=head->next;
        }
        else break;
    }
    head->next=NULL;
    while(p->next!=NULL)
    {
        printf("%d",p->data);
        p=p->next;
    }
    return 1;
}