问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

求具体的数据结构实验报告: 将若干城市的信息存入一个带头结点的单链表,结点中的城市信息包括城市名、

发布网友 发布时间:2022-04-30 15:19

我来回答

2个回答

热心网友 时间:2023-10-08 17:18

#include <stdio.h>
#include <string.h>
#include <math.h>
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 ’s old name\n ");
scanf( "%s ",cityName);
fflush(stdin);

p = head;
while (p)
{
result = strcmp(p-> cityName,cityName);
if (0 == result)
{
printf( "please input city ’s new name!!\n ");
scanf( "%s ",&p-> cityName);
fflush(stdin);
printf( "please input city ’s 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 ’s name\n ");
scanf( "%s ",cityName);
fflush(stdin);

while (p)
{
result = strcmp(p-> cityName,cityName);
if (0 == result)
{
printf( "city ’s 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 ’s 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 ");
}

热心网友 时间:2023-10-08 17:18

多谢楼主及上位仁兄~~~
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
arrive in和arrive at 有什么区别? 磁力泵为什么可空转? 为什么不让衬氟塑料磁力泵空转?怎样提升设备稳定性? 工业软管泵 塑料磁力泵为什么不能空转 求推荐男主和女配在一起的小说? 《红衣天下》txt全集下载 检测公司检测哪些 检测公司是怎么样的 检测公司属于什么企业 被永久封了。绑定的银行卡怎样解绑? 银行卡绑微信被限制, 微信能解绑银行卡吗? 被注销银行卡会解绑吗? 冻结银行卡怎么解绑? 被封期间可以解绑银行卡吗(没有永久封)? 被封如何解绑银行卡 被限制登录了,怎样才能解绑银行卡? 被封了,如何解绑银行卡呢? 被永久封了。绑定的银行卡怎样解绑? 冻结银行卡怎么解绑? 被封期间可以解绑银行卡吗(没有永久封)? 被永久封了。绑定的银行卡怎样解绑? 怎样才能让腾讯会议上的麦和视频不能用2020? 英皇乐理5级有9个学分是什么意思 英皇钢琴五级相当于国内的几级 考过了英皇五级乐理的人麻烦回应一下 邮政交养老保险咋交 英皇乐理5级考试 英皇考级140分是什么意思 数据结构 线性表操作《实验报告》,有人会吗 携程网就是垃圾,抢票这么久都没抢到 松松总动员加好友? 松松总动员180关高级怎么过 松松总动员毛怪和巴斯光年选哪个 仁者爱人有礼者敬人什么意思? 仁者爱人有礼者敬人的意思? 仁者爱人,有礼者敬人―释义 仁者爱人,有礼者敬人的意思是什么? 仁者爱人,有礼者敬人的含义是什么? ...以礼存心。仁者爱人,有礼者敬人。爱人者人恒爱之,敬人者人恒敬之... 爱人若爱其身。仁者爱人,有礼者敬人。与人善言,暖于布帛,伤 人以言... 仁者爱人的原文翻译!急!急!急! 仁者爱人,有礼者敬人,的意思? 爱人若爱其身不迁怒不贰过仁者爱人,有礼者敬利与人善言,暖于布帛伤人... 仁者爱人文言文翻译 君子以仁存心,以礼存心.仁者爱人,有礼者敬人.爱人者人恒爱之,敬人者... 仁者爱人,有礼者敬人是什么意思? 不迁怒不贰过爱人若爱其身仁者爱人有礼者敬人告诉我们什么道理 古文今译:仁者爱人,有礼者敬人。