求具体的数据结构实验报告: 将若干城市的信息存入一个带头结点的单链表,结点中的城市信息包括城市名、从上面问题中接下来:城市的位置坐标.要求:(1)、给定一个城市名,返回其位

来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/20 18:11:50
求具体的数据结构实验报告:将若干城市的信息存入一个带头结点的单链表,结点中的城市信息包括城市名、从上面问题中接下来:城市的位置坐标.要求:(1)、给定一个城市名,返回其位求具体的数据结构实验报告:将若

求具体的数据结构实验报告: 将若干城市的信息存入一个带头结点的单链表,结点中的城市信息包括城市名、从上面问题中接下来:城市的位置坐标.要求:(1)、给定一个城市名,返回其位
求具体的数据结构实验报告: 将若干城市的信息存入一个带头结点的单链表,结点中的城市信息包括城市名、
从上面问题中接下来:城市的位置坐标.要求:
(1)、给定一个城市名,返回其位置坐标;
(2)、给定一个位置坐标P和一个距离D,返回所有与P的距离小于等于D的城市.
多谢各位大大的,很急………………………………………………

求具体的数据结构实验报告: 将若干城市的信息存入一个带头结点的单链表,结点中的城市信息包括城市名、从上面问题中接下来:城市的位置坐标.要求:(1)、给定一个城市名,返回其位
#include
#include
#include
typedef int Length;
typedef struct {
int x;
int y;
}coordinate;
typedef struct cityInfo {
char cityName[10];
coordinate cityCoor;
struct cityInfo* next;
}citylink;
void addCity(citylink*);
void insertCity(citylink*);
void delCity(citylink);
void amendCity(char*);
void list(void);
void coordinateSureCityname(void);
void nearerCity(coordinate,Length);
void shortestCitys(void);
citylink *head;
citylink *end;
void addCity(citylink* newCity)
{
end-> next = newCity;
end = newCity;
newCity-> next = NULL;
}
void insertCity(citylink* newcity)
{
int number,i;
citylink *p,*q;
p = head;
printf( "insert where\n ");
scanf( "%d ",&number);
for(i = 1;i < number;i++)
{
p = p-> next;
}
q = p-> next;
p-> next = newcity;
newcity-> next = q;
}
void delCity()
{
int number,i;
citylink *p;
p = head;
printf( "please input the number of city you want to del\n ");
scanf( "%d ",&number);
if(1 == number)
{
head = head-> next;
}
for(i = 2;i < number;i++)
{
p = p-> next;
}
p-> next = p-> next-> next;
}
void amendCity()
{
int x,y,result;
citylink *p;
char cityName[10];
printf( "please in put city 鈥檚 old name\n ");
scanf( "%s ",cityName);
fflush(stdin);
p = head;
while (p)
{
result = strcmp(p-> cityName,cityName);
if (0 == result)
{
printf( "please input city 鈥檚 new name!\n ");
scanf( "%s ",&p-> cityName);
fflush(stdin);
printf( "please input city 鈥檚 new coordinate like this 88,99!\n ");
scanf( "%d,%d ",&x,&y);
p-> cityCoor.x = x;
p-> cityCoor.y = y;
break;
}
p = p-> next;
}
if (result != 0)
{
printf( "There have not this city ");
}
}
void coordinateSureCityname(void)
{
int result;
citylink *p;
char cityName[10];
p = head;
printf( "please in put city 鈥檚 name\n ");
scanf( "%s ",cityName);
fflush(stdin);
while (p)
{
result = strcmp(p-> cityName,cityName);
if (0 == result)
{
printf( "city 鈥檚 coordinate is %d,%d ",p-> cityCoor.x,p-> cityCoor.y);
}
p = p-> next;
}
if (result != 0)
{
printf( "There has not such city ");
}
}
void nearerCity()
{
citylink* p;
int temp,x,y;
coordinate coord;
int Length;
printf( "please input coordinate like this 88,99\n ");
scanf( "%d,%d ",&x,&y);
coord.x = x;
coord.y = y;
fflush(stdin);
printf( "please input length\n ");
scanf( "%d ",&Length);
p = head;
while(p)
{
temp = sqrt(pow((coord.x - p-> cityCoor.x),2) + pow((coord.y - p-> cityCoor.y),2));
if (temp < Length)
{
printf( "city name :%s\n ",p-> cityName);
}
p = p-> next;
}
}
void list(void)
{
citylink *p;
p = head;
while(p)
{
printf( "city 鈥檚 name = %s,citys coordinate = %d ,%d\n ",p-> cityName,p-> cityCoor.x,p-> cityCoor.y);
p = p-> next;
}
}
void main(void)
{
citylink city1;
citylink city2;
citylink city3;
citylink city4;
citylink city5;
citylink city6;
citylink city7
head = &city1;
city1.cityCoor.x = 12;
city1.cityCoor.y = 22;
strcpy(city1.cityName,"city1 " );
city1.next = &city2;
city2.cityCoor.x = 28;
city2.cityCoor.y = 95;
strcpy(city2.cityName,"city2 " );
city2.next = &city3;
city3.cityCoor.x = 32;
city3.cityCoor.y = 17;
strcpy(city3.cityName,"city3 " );
city3.next = &city4;
city4.cityCoor.x = 58;
city4.cityCoor.y = 98;
strcpy(city4.cityName,"city4 " );
city4.next = &city5;
city5.cityCoor.x = 31;
city5.cityCoor.y = 67;
strcpy(city5.cityName,"city5 " );
city5.next = &city6;
city6.cityCoor.x = 21;
city6.cityCoor.y = 99;
strcpy(city6.cityName,"city6 " );
city6.next = NULL;
head = &city1;
end = &city6;
city7.cityCoor.x = 19;
city7.cityCoor.y = 84;
strcpy(city7.cityName,"city7 " );
list();
printf( "\n ");
}