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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog