利用递归创建链表

来源:互联网 发布:厦门软件学院怎么样 编辑:程序博客网 时间:2024/06/07 23:06
#include<stdio.h>#include<stdlib.h>typedef struct node{int date;struct node *next;}node;node * Creatlink(struct node * tp,int k);int main(){int tmp;struct node * head=NULL, *tail=NULL;head=Creatlink(tail,6);for(tail=head;tail;tail=tail->next)printf("%d ",tail->date);printf("\n");return 0;}node * Creatlink(struct node * tp,int k){if(k==0)return NULL;else{tp=(struct node *)malloc(sizeof(node));tp->date=k;tp->next=Creatlink(tp->next,k-1);}return tp;}

0 0
原创粉丝点击