这是全部代码:(正确的)
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
//尾插法
typedef struct _Node
{
int data;
struct _Node* next;
}Node;
Node* Createlist(int n)
{
int i = 0;
Node* head, * tail, * p;
head = tail = NULL;
for (i = 0; i < n; i++)
{
p = (Node*)malloc(sizeof(Node));
p->next = NULL;
scanf("%d", &p->data);
if (head == NULL)
{
head = tail = p;
}
else
{
tail->next = p;
tail = p;
}
}
return head;
}
void Printlist(Node* head)
{
while (head != NULL)
{
printf("%d -> ", head->data);
head = head->next;
}
printf("NULL");
}
int main()
{
int n;
scanf("%d", &n);
Node* head = NULL;
head = Createlist(n);
Printlist(head);
return 0;
}
但是 ,这一段代码中:
typedef struct _Node
{
int data;
struct _Node* next;
}Node;
这里的struct _Node* next;换为Node *next;
typedef struct _Node
{
int data;
Node *next;
}Node;
为什么编译器会报错;会出现好多错误;