求具体的数据结构实验报告: 将若干城市的信息存入一个带头结点的单链表,结点中的城市信息包括城市名、
来源:学生作业帮 编辑:神马作文网作业帮 分类:英语作业 时间:2024/11/16 14:20:10
求具体的数据结构实验报告: 将若干城市的信息存入一个带头结点的单链表,结点中的城市信息包括城市名、
从上面问题中接下来:城市的位置坐标.要求:
(1)、给定一个城市名,返回其位置坐标;
(2)、给定一个位置坐标P和一个距离D,返回所有与P的距离小于等于D的城市.
多谢各位大大的,很急………………………………………………
从上面问题中接下来:城市的位置坐标.要求:
(1)、给定一个城市名,返回其位置坐标;
(2)、给定一个位置坐标P和一个距离D,返回所有与P的距离小于等于D的城市.
多谢各位大大的,很急………………………………………………
#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 ");
}
#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 ");
}
关于数据结构的一道题试写一算法,将指针s指向的无头结点的单链表链接到带头结点单链表L的最后一个结点之后.函数原型使用St
已知带头结点的单链表L,指针P指向L链表中的一个结点为(非首结点、非尾结点),
数据结构已知指针P指向双向链表中的一个结点(非首结点、非尾结点),则:(1)将结点S插入在P结点的直接
一棵树T中,包括一个度为1的结点,两个度为2的结点,三个度为3的结点,四个度为4的结点和若干叶子结点,则T的叶结点数为
高中地理必须掌握的城市及城市的信息
美国华盛顿城市的英文信息
数据结构:rear是指向非空带头结点的循环单链表的尾指针,则删除起始点的操作可表示为()选择哪个求大神
两个带头结点的循环单链表ha和hb,设计算法将hb链在ha合成一个带头结点的单链表hc.要求不再开辟新的空间
数据结构题目:双链表中,在*p结点之后插入一个结点*s的操作是?
只有一个根结点的数据结构是线性结构
已知带表头结点的单链表L,指针P指向L链表中的一个结点(非首、尾结点):删除P结点的语句序列是?
在一个带头结点的单循环链表中,p指向尾结点的直接前驱,则指向头结点的指针head可用p表示为head=