• C语言数据结构课程设计-城市链表。基本功能已经完成
  • 此程序还有一些BUG:一个坐标只对应一个城市,不能重复。
  • 希望大家好好学习数据结构
#include <stdio.h>
#include <stdlib.h>
#include <string.h>// 构建城市链表
/*** 城市的属性:*  name:城市名*  area:城市的面积*  peopleCount:城市人口的数量*  top:城市的排行*  x:x轴距离*  y:y轴距离*/
typedef struct City{char name[30];float area;int peopleCount;int top;int x;int y;char feature[50];struct City *next;
}City,*CityList;// 初始化城市表(over)
CityList init(){City* head;head = (CityList)malloc(sizeof(City));if(head == NULL){printf("开辟失败");return NULL;}head->next = NULL;
//    printf("%d", sizeof(City));
//    printf("%d", sizeof(head));return head;
}//添加城市(over)
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){printf("城市等级输入错误,请重新输入:");scanf("%d",&newCity->top);}printf("\n");printf("请输入城市特色:");scanf("%s",&newCity->feature);newCity->next = NULL;head->next = newCity;printf("添加成功!\n");
}//展示所有城市信息(over)
void showCity(CityList head){City *temp = head->next;
//    printf("当然结构体的大小:%d\n", sizeof(temp));if(temp == NULL){printf("城市为空,无法输出!\n");return;}printf("\n---------- 正在生成城市清单 ---------\n");while (temp != NULL){printf("城市名:%s\n",temp->name);printf("城市人口(万人):%d\n",temp->peopleCount);printf("城市面积(平方千米):%.3f\n",temp->area);printf("城市等级:%d\n",temp->top);printf("城市X坐标:%d\n",temp->x);printf("城市Y坐标:%d\n",temp->y);printf("城市特色:%s\n",temp->feature);printf("------------------------------\n");temp = temp->next;}
}//根据城市名来删除城市(over)
void delCity(CityList head){printf("\n------------------------------\n");char cityName[10];char choose;printf("请输入你要删除的城市名:");scanf("%s",&cityName);// 找到要删除城市的前一个城市while(strcmp(head->next->name,cityName)){head = head->next;if (head->next == NULL){printf("没有你想要删除的城市,程序即将返回主页面\n");return;}}CityList temp = head; // 删除城市的前一个城市CityList del = head->next; // 删除城市printf("你将删除的城市信息:\n");printf("城市名:%s\n",del->name);printf("城市人口(万人):%d\n",del->peopleCount);printf("城市面积(平方千米):%.3f\n",del->area);printf("城市等级:%d\n",del->top);printf("城市X坐标:%d\n",del->x);printf("城市Y坐标:%d\n",del->y);printf("城市特色:%s\n",del->feature);printf("------------------------------\n");printf("\n你确定要删除[Y-N]:");scanf("%s",&choose);if (choose == 'Y'){temp->next = del->next;free(del);printf("删除成功\n");} else{printf("删除取消\n");return;}}// 菜单(over)
void menu(){printf("\n******* 欢迎来到城市信息管理系统 *******\n");printf("<--- 1. 添加城市 -->\n");printf("<--- 2. 删除城市 -->\n");printf("<--- 3. 修改城市 -->\n");printf("<--- 4. 查询城市 -->\n");printf("<--- 5. 坐标查询 -->\n");printf("<--- 6. 退出程序 -->\n");printf("****************************\n");
}// 修改城市信息(over)
void updateCity(CityList head){if (head->next == NULL){printf("城市链表为空,请先添加城市。。。\n");return;}printf("<--- 这里是修改城市信息服务! --->\n");char name[10];printf("请输入你要修改城市的名字:");scanf("%s",&name);while (strcmp(head->name,name)){head = head->next;}if (head == NULL){printf("没有此城市,将退出此功能。。。\n");return;}City *temp = head;printf("\n----------- 修改城市信息 ----------\n");printf("请输入城市名:");scanf("%s",&temp->name);printf("请输入面积(平方千米):");scanf("%f",&temp->area);printf("请输入人口数(万人):");scanf("%d",&temp->peopleCount);printf("请输入城市X坐标:");scanf("%d",&temp->x);printf("请输入城市y坐标:");scanf("%d",&temp->y);printf("请输入城市等级:[1-5]:");scanf("%d",&temp->top);while (temp->top>5 || temp->top <1){printf("城市等级输入错误,请重新输入:");scanf("%d",&temp->top);}printf("请输入城市特色:");scanf("%s",&temp->feature);printf("******** 修改信息成功 ********\n");
}// 给定一个坐标P和距离D,返回所有与P的距离小于D的城市(over)
void length(CityList head){CityList cityList = head->next;printf("\n********* 搜索范围之内的城市 *********\n");int x,y,D;printf("请输入坐标:\n");printf("x =");scanf("%d",&x);printf("y =");scanf("%d",&y);printf("请输入距离 D:");scanf("%d",&D);printf("正在为你返回符合城市:\n");printf("----------*************----------\n");while (cityList != NULL){if ((cityList->x * cityList ->x) + (cityList->y * cityList ->y) <= D * D){printf("城市名:%s\n",cityList->name);printf("城市人口(万人):%d\n",cityList->peopleCount);printf("城市面积(平方千米):%.3f\n",cityList->area);printf("城市等级:%d\n",cityList->top);printf("城市X坐标:%d\n",cityList->x);printf("城市Y坐标:%d\n",cityList->y);printf("城市特色:%s\n",cityList->feature);printf("------------------------------\n");}cityList = cityList->next;}
}int main(){int selet;CityList cityList = init();while (1){menu();printf("<--请输入你的选择[1-6]:");scanf("%d",&selet);while (selet > 6 || selet < 1){printf("输入错误,请重新输入[1-6]:");scanf("%d",&selet);}switch (selet){case 1:addCity(cityList);break;case 2:delCity(cityList);break;case 3:updateCity(cityList);break;case 4:showCity(cityList);break;case 5:length(cityList);break;case 6:printf("****** 欢迎使用 ******");exit(0);}}
}

数据结构课程设计 - 城市链表相关推荐

  1. 算法与数据结构课程设计城市公交管理系统(C、C++)

    城市公交管理系统 项目功能模块(需要源码请私信) 1.添加功能: [1]添加公交站,将站点信息写入stations.txt中: [2]添加交通路线,将路线信息写入bus.txt中: 2.删除功能: [ ...

  2. 猴子吃桃问题c语言链表,数据结构课程设计--猴子吃桃子问题.doc

    Data organization curriculm project 数据结构课程设计 设计题目: 猴子吃桃子问题 专业班级: 通信工程0804班 学生学号: 0909082421 学生姓名: 王 ...

  3. 数据结构课程设计:顺序结构、动态链表结构下的一元多项式的加法、减法、乘法的实现...

    原来做的数据结构课程设计,今天整理资料时偶然发现了,自己留着没啥意思,共享一下吧,互相交流学习 要求 设有一元多项式Am(x)和Bn(x). Am(x)=A0+A1x1+A2x2+A3x3+- +Am ...

  4. 大学数据结构课程设计题目

    数据结构课程设计题目 1.         飞机订票系统(限1 人完成) 任务:通过此系统可以实现如下功能: 录入: 可以录入航班情况(数据可以存储在一个数据文件中,数据结构.具体数据自定) 查询: ...

  5. C/C++数据结构课程设计安排

    C/C++数据结构课程设计安排 数据结构课程设计安排 课程设计学时:32学时 课程设计目的:综合应用数据结构课程中所学的数据结构:线性表.栈.队列.数组.广义表.树.二叉树.图.查找表中的一种或多种数 ...

  6. “数据结构”课程设计题目

    "数据结构"课程设计题目 1.城市链表 [问题描述] 将若干城市的信息,存入一个带头结点的单链表.结点中的城市信息包括:城市名,城市的位置坐标.要求能够利用城市名和位置坐标进行有关 ...

  7. 设树采用孩子兄弟表示法存放.用类c语言设计算法计算树的高度.,(数据结构课程设计分类题目.doc...

    (数据结构课程设计分类题目 线性表 顺序表: 1.设有一元素为整数的线性表L=(a1,a2,a3,-,an),存放在一维数组A[N]中,设计一个算法,以表中an作为参考元素,将该表分为左.右两部分,其 ...

  8. c语言数据结构课程设计停车场管理系统,数据结构课程设计报告停车场管理系统...

    <数据结构课程设计报告停车场管理系统>由会员分享,可在线阅读,更多相关<数据结构课程设计报告停车场管理系统(8页珍藏版)>请在人人文库网上搜索. 1.数据结构课程设计报告系 别 ...

  9. C/C++《数据结构课程设计》任务书[2022-12-27]

    C/C++<数据结构课程设计>任务书[2022-12-27] <数据结构课程设计>任务书 一.任务总体安排: 班级 设计时间 地点 指导老师 21软件开发 17周每周一至周五五 ...

最新文章

  1. Json反序列化与Java泛型
  2. secureCRT The remote system refused the connection. .
  3. 中艺人脸识别考勤机使用方法_人脸识别考勤机的使用方法及注意事项 - 全文
  4. JDK、Tomcat、Maven配置
  5. 什么是clearfix?
  6. 【VS2010学习笔记】【函数学习】一(MFC+OpenCV2.4.7读取摄像头之WM_TIMER消息处理函数的添加问题)
  7. 连不通linux 27017,mongo --host 127.0.0.1:27017 报错连不上
  8. SQL Prompt10 安装激活教程,让你写sql 如鱼得水
  9. 计算机表格怎么互换,excel怎么把单元格交换位置
  10. VC++界面编程之--实现工具栏自定义皮肤
  11. 微信小程序的基本操作
  12. 关于XShell下载安装和连接Ubuntu(linux)
  13. 零基础做一个微信答题小程序(三)
  14. Vue之watch监听
  15. SQL2005导入数据至2000的问题
  16. 星星之火-30:什么是WCDMA的伪随机码与扰码?
  17. 银保监会计算机类专业知识,国家公务员局2019中国银保监会国考内容:计算机类专业知识...
  18. 当Java虚拟机遇上Linux Arena内存池
  19. 将输入值为非数字的字符替换为空
  20. 从麦当劳的管理谈品牌的细节塑造

热门文章

  1. 美的 java 薪酬,美的集团iHR巧解“薪酬管理”难关——薪资核算发放
  2. 三天痛别八位院士!中科院院士、药学家蒋华良英年早逝,终年57岁
  3. 本地字节序和网络字节序
  4. KB5008212无法共享打印机解决办法
  5. 小程序setdata优化_支付宝小程序扩展能力 附录 1:优化 setData 逻辑方案明细
  6. 个人信息泄露 大病难治
  7. 张秋民老师6月9号给海油集团讲授《金字塔思维与公文写作》圆满结束
  8. FPGA入门学习笔记(十四)Vivado实现数码管段码显示以及动态扫描
  9. CF EDU138 D(数论) ,牛练104C(DP) ,焦作F. Honeycomb(复杂建图,BFS最短路)
  10. Adobe Photoshop 画笔无压感