现在的位置: 首页 > 综合 > 正文

顺序建立链表

2018年04月15日 ⁄ 综合 ⁄ 共 412字 ⁄ 字号 评论关闭
#include <stdio.h>
#include <stdlib.h>
struct node
{
    int date;
    struct node *next;
}*head=NULL,*q=NULL,*t=NULL,*bl=NULL,*p=NULL;
//head头 q尾 t中间  bl中间
int main()
{
    int i,n;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        p=(struct node *)malloc(sizeof(struct node));
        if(head==NULL)
        {
            head=p;
        }
        else
        {
           t->next=p;
           p->next=NULL;
        }
        scanf("%d",&p->date);
        t=p;
    }
	p=head;
    while(p!=NULL)
    {
        printf("%d",p->date);
        if(p->next!=NULL)
           {
               printf(" ");
           }
        else
        {
            printf("\n");
        }
        p=p->next;
    }
    return 0;
}

【上篇】
【下篇】

抱歉!评论已关闭.