标签:sizeof head type 自己 bsp next 添加 pass last
描述:pass
#include<stdio.h> #include <stdlib.h> typedef struct _node{ int value; struct _node *next; } node; node* creat(); node* print(node* L1); int main(){ node *L1; L1 = creat(); print(L1); }
node* creat(){//这个是堆桟(倒序添加的 ,先加的在后面,后加的在前面) int number; node*end=NULL,*head; scanf("%d",&number); if(number!=-1){ end=(node*)malloc(sizeof(node)); end->value=number; end->next=NULL; } head=end; //创造了第一个链表节点; while(number!=-1){ scanf("%d",&number); if(number!=-1){ node *p; p=(node*)malloc(sizeof(node)); p->value=number; p->next=end; //生成了一个临时节点; head=p; end=p; //将两个链表节点链接起来了; } } return head; }
node* print(node* L1){ node*last=L1; if(last==NULL){ printf("NULL"); return 0; } while(last->next!=NULL){ printf("%d ",last->value); last=last->next; } printf("%d ",last->value); }
标签:sizeof head type 自己 bsp next 添加 pass last
原文地址:https://www.cnblogs.com/home979/p/9225685.html