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 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)