- 论坛徽章:
- 0
|
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
typedef struct Node /*结点类型定义*/
{
char name[50];
int x;
int y;
struct Node* next;
} Node, *Linkcity;
void Initcity(Linkcity *L) /*初始化链表*/
{
*L=(Linkcity)malloc(sizeof(Node));
(*L)->next=NULL;
}
Linkcity Createcity(Linkcity L) /*创建链表*/
{
Node *s,*r;
r=L,s=NULL;
int x=0;
int y=0;
int flag=1;
while(flag)
{
s=(Node *)malloc(sizeof(Node));
printf("请输入城市名\n");
scanf("%s",&s->name);
if(!strcmp(s->name,"out"))
{
flag=0;
}
else
{
printf("请输入城市x y坐标\n");
scanf("%d %d",&x,&y);
s->x=x;s->y=y;
s->next=r->next;
r=s;
}
}
return L;
}
void main()
{
Linkcity L=NULL;
Initcity(&L);
Createcity(L);
}
这个完全能通过编译,运行也没什么问题,但是为什么我不能将
void Initcity(Linkcity *L) /*初始化链表*/
{
*L=(Linkcity)malloc(sizeof(Node));
(*L)->next=NULL;
}
改成
void Initcity(Linkcity L) /*初始化链表*/
{
L=(Linkcity)malloc(sizeof(Node));
L->next=NULL;
}
感觉没什么变化啊,就是通不过编译了,希望指教!困扰多时! |
|