题解 | #牛牛逆序输出#单向链表(用递归)

牛牛的单向链表

http://www.nowcoder.com/practice/95559da7e19c4241b6fa52d997a008c4

#include<stdio.h>
#include<stdlib.h>
struct output{
    int data;    //数据域
    struct output* next;    //指针域
};
//创建新结点的结构体指针
void creat_newcode( struct output *head, int n){
    for(int i = 1;i == 1;){
    if(n!=0){
    struct output *newtie = NULL;
    newtie = (struct output*)malloc(sizeof(struct output));//分配空间
    scanf("%d",&(newtie->data));//传入数据域
    head->next = newtie;//链接
    printf("%d ",newtie->data);
    creat_newcode(newtie , n-1);}
    i--;
}
}
int main(){
    int n;
    scanf("%d\n",&n);
    struct output *head = NULL;//创建头指针
    head = (struct output*)malloc(sizeof(struct output));//给头指针分配空间
    creat_newcode(head,n);

    return 0;
}
全部评论

相关推荐

LemontreeN:有的兄弟有的我今天一天面了五场,4个二面一个hr面
投递字节跳动等公司7个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务