gpt4 book ai didi

c - 数据结构基础程序

转载 作者:行者123 更新时间:2023-11-30 20:26:37 24 4
gpt4 key购买 nike

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

void insertion(int X,Node *l);
void display( Node *y);

void display(Node *y)
{
printf("\n Your Node Contains \n Data : %d \t Pointer : %d \n ",y->data,y->sp);
}

void insertion(int X,Node *l)
{
l->data=X;
l->sp=NULL;
}

typedef struct
{
int data;
int *sp;
}Node;

int main(void)
{
int kl; Node *j;
printf("\n Enter the data you like to put :");
scanf("%d",&kl);
insertion(kl,j);
display(j);
return 0;
}

编译期间出现错误 - 第 3、4、5、9 行上的“未知类型节点”。为什么 ?我无法纠正错误。我最近才开始使用数据结构,这只是一个节点数据插入程序。

最佳答案

修复非常简单,您必须在尝试使用结构之前对其进行 typedef。

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

typedef struct // You cant use the Node keyword before this
{
int data;
int *sp;
}Node;

void insertion(int X,Node *l);
void display( Node *y);

void display(Node *y)
{
printf("\n Your Node Contains \n Data : %d \t Pointer : %d \n ",y->data,y->sp);
}

void insertion(int X,Node *l)
{
l->data=X;
l->sp=NULL;
}


int main(void)
{
int kl; Node *j;
printf("\n Enter the data you like to put :");
scanf("%d",&kl);
insertion(kl,j);
display(j);
return 0;
}

关于c - 数据结构基础程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25270139/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com