【发布时间】:2014-03-28 02:57:10
【问题描述】:
我正在使用以下代码,但它显示错误:预期的构造函数、析构函数或 * 标记之前的类型转换。 它显示了函数原型和函数声明行中的错误。
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
node *insert(node *head); // the compiler is showing error here
main()
{
int dat;
char x,ch;
struct node_type
{
int data;
node_type *next;
};
typedef struct node_type node;
// node *head;
node *temp;
// head= NULL;
temp=NULL;
printf("do u wanna enter a new node? \n");
scanf("%c", &x);
if (x=='y' or x=='Y')
{
temp=(node *)malloc(sizeof(node));
printf("enter the data: \n");
scanf("%d ", &dat);
temp->data= dat;
temp->next = NULL;
}
printf("do u want to insert another element?\n");
scanf("%c ", &ch);
if( ch=='y' or ch=='Y')
{
insert(*temp);
}
getch();
}
node *insert(node *temp)
{
int dat;
char ch;
node *new;
new=(node *)malloc(sizeof(node));
printf("enter the data: ");
scanf(" %d ", &dat);
new->data=dat;
new->next=temp;
temp=new;
printf("do u want to insert another element?\n");
scanf("%c ", &ch);
if (ch == 'y' or ch == 'Y')
{
insert(*temp);
}
else
return temp;
}
什么是错误以及如何纠正它?
【问题讨论】:
-
请至少是
int main(void)! -
“节点”在哪里定义?是否包含了它的头文件?
-
您可能希望完整引用收到的错误消息。
-
有什么特别的原因你不只使用 std::list 吗?
-
这看起来不像 C++。
标签: c++ c insert linked-list