0
点赞
收藏
分享

微信扫一扫

C语言简单的尾插法

非宁静不致远 2022-03-11 阅读 45

#include <stdio.h>
#include <stdlib.h>
struct s{
    int a;
    s *next;
};
int main()
{
    int n,i;
    s *head,*p,*r;
    scanf("%d",&n);
    head=(s*)malloc(sizeof(s));
    head->next=NULL;
    r=head;
    for(i=0;i<n;i++)
    {
        p=(s*)malloc(sizeof(s));
        scanf("%d",&p->a);
        p->next=r->next;
        r->next=p;
        r=p;
    }
    head=head->next;
    while(head!=NULL)
    {
        printf("%d ",head->a);
        head=head->next;
    }
}

举报

相关推荐

0 条评论