返回一级指针 创建链表

来源:互联网 发布:投标报价软件 编辑:程序博客网 时间:2024/06/01 09:46

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


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


0 0
原创粉丝点击