- C语言数据结构课程设计-城市链表。基本功能已经完成
- 此程序还有一些BUG:一个坐标只对应一个城市,不能重复。
- 希望大家好好学习数据结构
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct City{
char name[30];
float area;
int peopleCount;
int top;
int x;
int y;
char feature[50];
struct City *next;
}City,*CityList;
CityList init(){
City* head;
head = (CityList)malloc(sizeof(City));
if(head == NULL){
printf("开辟失败");
return NULL;
}
head->next = NULL;
return head;
}
void addCity(CityList head){
CityList newCity = (City *)malloc(sizeof(City));
while (head->next != NULL){
head = head->next;
}
printf("\n----------- 添加一个城市 ----------\n");
printf("请输入城市名:");
scanf("%s",&newCity->name);
printf("请输入面积(平方千米):");
scanf("%f",&newCity->area);
printf("请输入人口数(万人):");
scanf("%d",&newCity->peopleCount);
printf("请输入城市X坐标:");
scanf("%d",&newCity->x);
printf("请输入城市y坐标:");
scanf("%d",&newCity->y);
printf("请输入城市等级:[1-5]:");
scanf("%d",&newCity->top);
while (newCity->top>5 || newCity->top <1)