qq_34378013 2016-03-22 10:48 采纳率: 14.3%
浏览 1617

C语言建立单链表的问题

 #include<stdio.h>
#include<stdlib.h>

struct node
{
    int num;
    int L;
    struct node *next;
};
typedef struct node LN;

typedef struct
{
    int num1[100];
    int L1;
}S;


void Creat1(S &p);
void Creat(LN *p);

void main()
{
    S p;
    LN *h;
    p.L1=0;
    int n;
    Creat(h);
    Creat1(p);
}


void Creat1(S &p)
{
    int a;
    printf("Input total number of list:");
    scanf("%d",&a);
    printf("\n");
    system("CLS");
    for(int i=0;i<a;i++)
    {
        printf("Input the %d one:",i+1);
        scanf("%d",&p.num1[i]);
        p.L1++;
    }
    system("CLS");
}


void Creat(LN *h)
{
    int a;
    LN *p;
    LN *b;
    printf("Input the number of the linklist:");
    scanf("%d",&a);
    h=(LN *)malloc(sizeof(LN));
    h->next=NULL;
    b=h;
    for(int i=0;i<a;i++)
    {
        printf("Input the %d number ",i+1);
        p=(LN *)malloc(sizeof(LN));
        scanf("%d",p->num);
        b->next=p;
        b=p;
        p->L++;
    }
    system("CLS");
    p->next=NULL;
}

在Creat函数中创建了一个单链表,那么我要怎么返回主函数,因为我是void一个Creat的函数,急求,谢谢各位大神了。

  • 写回答

2条回答 默认 最新

  • 梦若痕 2016-03-22 12:05
    关注

    c风格的话,参数得传二级指针,一级指针的话,是不行的。c++风格的话,可以传引用。

    评论

报告相同问题?

悬赏问题

  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛