資源簡介
1.若干城市的信息存入一個帶頭結點的單鏈表,結點中的城市信息包括城市名、城市的位置坐標。要求:
(1)給定一個城市名,返回其位置坐標。
(2)給定一個位置坐標P和一個距離D,返回所有與P的距離小于等于D的城市。
代碼片段和文件信息
#include
#include
#include?
#include
#define?NULL?0
typedef?struct?Node
{
char?name[20];
int?xy;
struct?Node?*next;
}Node*linkList;
void?InitList(linkList?*l)
{
(*l)=(linkList)malloc(sizeof(Node));
(*l)->next=NULL;
}
void?cj(linkList?L)
{
char?city[20];
int?jdwd;
Node?*r*s;
int?flag=1;
r=L;
printf(“當輸入城市為0時輸入結束\n“);
while(flag)
{
printf(“請輸入存入的城市:“);
scanf(“%s“city);
if(strcmp(“0“city)!=0)
{
printf(“該城市的坐標為:“);
scanf(“%d%d“&jd&wd);
s=(Node*)malloc(sizeof(Node));
strcpy(s->namecity);
s->x=jd;
s->y=wd;
r->next=s;
r=s;
}
else
{
flag=0;
r->n
- 上一篇:分數計算器C++
- 下一篇:CVSD解碼c語言代碼
評論
共有 條評論