显示读取访问权限冲突,不知道为什么。
#include
#include
#include
typedef struct node {
int data;
struct node* next;
}node, * Linklist;
void creatList_1(node* l, int n) {//头插法
node* p;
int i,j;
p = NULL;
l = (Linklist)malloc(sizeof(node));
l->next = NULL;
for (i = n;i > 0;--i) {
p = (Linklist)malloc(sizeof(node));
scanf_s("%d", &j);
p->data = j;
p->next = l->next;
l->next = p;
}
}
void PrintList(node* l) {
printf("内容为:");
while (l->next != NULL)
{
printf("%d ", l->next->data);
l = l->next;
}
printf("\n");
}
void main() {
Linklist La;
La = (node*)malloc(sizeof(node));//动态分配内存
creatList_1(La, 7);//头插法,倒序
PrintList(La);
}
12行删掉就行了。main里已经创建了头结点啦
怎么问好几个啊,测试过了,12行删掉就可以了
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
typedef struct node {
int data;
struct node* next;
}node, * Linklist;
void creatList_1(node* l, int n) {//头插法
node* p;
int i,j;
p = NULL;
//l = (Linklist)malloc(sizeof(node));
l->next = NULL;
for (i = n;i > 0;--i) {
p = (Linklist)malloc(sizeof(node));
scanf("%d", &j);
p->data = j;
p->next = l->next;
l->next = p;
}
}
void PrintList(node* l) {
printf("内容为:");
while (l->next != NULL)
{
printf("%d ", l->next->data);
l = l->next;
}
printf("\n");
}
int main() {
Linklist La;
La = (node*)malloc(sizeof(node));//动态分配内存
creatList_1(La, 7);//头插法,倒序
PrintList(La);
}