代码:
#define _CRT_SECURE_NO_WARNINGS
#include "stdio.h"
#include "stdlib.h"
typedef struct
{
int value;
struct node* next;
}node;
int creatlistf(node* l, int data[], int length)
{
node* p;
if (l)
{
l->next = NULL;
for (int i = 0; i < length; i++)
{
p = (node*)malloc(sizeof(node));
p->value = data[i];
p->next = l->next;
l->next = p;
}
return 1;
}
return 0;
}
int creatlistr(node* l, int data[], int length)
{
node* r, *p;
if (l)
{
l->next = NULL;
r = l;
for (int i = 0; i < length; i++)
{
p = (node*)malloc(sizeof(node));
p->value = data[i];
printf("%d\t", p->value);
r->next = p;
r = p;
}
r->next = NULL;
return 1;
}
return 0;
}
void displist(node* l)
{
node* p;
if (l)
{
p = l;
while (p->next != NULL)
{
p = p->next;
printf("%d\t", p->value);
}
}
}
int main()
{
node* l;
l = (node*)malloc(sizeof(node));
int x[10] = { 1,2,3,4,5,6,7,8,9,10 },STATUS=0;
STATUS = creatlistf(&l, x, 10);
displist(&l);
return 0;
}
具体报错如下(软件为vs),因为是xin shou,希望能点名原因和修改方法,谢谢!翻译是是l的两个堆栈已损坏。
谢谢!