33,028
社区成员
发帖
与我相关
我的任务
分享#include "stdio.h"
#include "stdlib.h"
typedef struct Lay{
int x;
struct Lay *next;
}Link,*List;
void Init(List *L);
void Insert(List L, int x);
void print(List L);
void main()
{
List p,l;;
int i;
Init(&l);
p=l;
for(i=0;i<10;i++)
{
Insert(p,i);
}
printf("\n");
print(l);
}
void Init(List *L)
{
*L = (List)malloc(sizeof(Link));
(*L)->next=NULL;
}
void Insert(List L,int x) //就是这里有问题
{
List temp;
temp = (List)malloc(sizeof(Link));
temp->x=x;
temp->next=L->next;
L->next=temp;
L=temp; //我每次L的内存地址有变了,但是为什么出来的时候是没变的
}
void print(List L)
{
for(L=L->next;L!=NULL;L=L->next)
printf("%d ",L->x);
printf("\n");
}
dio.h"
#include "stdlib.h"
typedef struct Lay{ int x; struct Lay *next; }Link,*List;
void Init(List *L);
void Insert(List *L, int x);
void print(List L);
void main() {
List p,l;;
int i; Init(&l); p=l;
for(i=0;i<10;i++)
{ Insert(&p,i); }
printf("\n");
print(l);
}
void Init(List *L)
{
*L = (List)malloc(sizeof(Link));
(*L)->next=NULL;
}
void Insert(List *pL,int x)
//就是这里有问题
{
List L=*pL;
List temp;
temp = (List)malloc(sizeof(Link));
temp->x=x; temp->next=L->next;
L->next=temp;
*pL=temp; //我每次L的内存地址有变了,但是为什么出来的时候是没变的
}
void print(List L)
{
for(L=L->next;L!=NULL;L=L->next)
printf("%d ",L->x); printf("\n");
}