数据结构 c语言版问题

来源:百度知道 编辑:UC知道 时间:2024/06/04 04:52:54
将若干城市的信息存入一个带头节点的单链表,节点中的城市信息包括城市名 城市的位置坐标。要求:
1 给定一个城市名,返回其位置坐标;
2 给定一个位置坐标P和一个距离D,返回所有与P的距离小于等于D的城市。

参考一下吧!!
#include<iostream>
#include<string.h>
#include<math.h>
#include<stdlib.h>
using namespace std;
typedef struct information{
char city_name[20];
int x;
int y;
struct information *next;
}location;
int main()
{
location *head,*p,*q;
char name[20];
int x,y;
int distence;
float less_D;
head=(location *)malloc(sizeof(location));
head->next=NULL;
cout<<"输入城市的名称和坐标:"<<endl;
cin>>name;
cin>>x;
cin>>y;
strcpy(head->city_name,name);
head->x=x;
head->y=y;
p=head;
q=head;
cin>>name;
cin>>x;
cin>>y;
while(strcmp(name,"no"))//输入no 0 0时结束
{
p=(location *)malloc(sizeof(location));