不利用函数直接构造链表

来源:互联网 发布:家电 进销存 源码 编辑:程序博客网 时间:2024/06/05 15:09

给定一批整数,以0作为结束标志且不作为节点,将其建成一个先进先出的链表


#include<stdio.h>#include<stdlib.h>typedef struct node{int date;struct node *next;}node;int main(){int tmp;struct node * head, *tail;head=(struct node *)malloc(sizeof(node));scanf("%d",&(head->date));tail=head;while(~scanf("%d",&tmp) && tmp){tail->next=(struct node *)malloc(sizeof(node));tail->next->date=tmp;tail=tail->next;}tail->next=NULL;for(tail=head;tail;tail=tail->next)printf("%d ",tail->date);printf("\n");return 0;}


0 0
原创粉丝点击