用C语言实现 坐标管理系统(类似于学生管理系统的功能)
2017-01-21 13:47
726 查看
这个程序的许多地方都可以照搬过去,主要就是链表的创建,插入,删除,排序。
#include<stdio.h> #include<time.h> #include<stdlib.h> #include<Windows.h> #include<malloc.h> #include<string.h> typedef struct point{ int rows; int cols; struct point *next; }point; void intipointlink(point *head); void showpoints(point head); void showonepoint(point head); void destroy(point *head); void insert(point *heads); point *found(point head, int oldrows, int oldcols); void *create(int rows, int cols); void *delete(point head, int rows, int cols); void showtopic(char *topic); void *ordering(point head); void *ordering(point head) { point *pi, *pj, *pt, t; for (pi = head.next; pi;pi=pi->next) for (pj = pi->next; pj; pj = pj->next) if (pi->rows > pj->rows) { t = *pi; *pi = *pj; *pj = t; pt = pi->next; pi->next = pj->next; pj->next = pt; } return pi; } void showtopic(char *topic) { char space[] = " "; printf("%s %s\n", space + (strlen(topic) / 2), topic); } void *create(int rows, int cols) { point *p; p = (point *)malloc(sizeof(point)); p->rows = rows; p->cols = cols; p->next = NULL; return p; } void showonepoint(point head) { printf("(%d %d)", head.rows, head.cols); } void showpoints(point head) { point *p; printf("\n当前坐标如下:\n"); for (p = head.next; p; p = p->next) { showonepoint(*p); } } void initpointlink(point *head) { int rows; int cols; point *p; if (head->next == NULL) { showtopic("请输入录入坐标(输入(0 0)结束录入)"); scanf("%d %d", &rows, &cols); fflush(stdin); while (rows&&cols) { p = create(rows, cols); head->next = p; head = p; showtopic("请输入录入坐标(输入(0 0)结束录入)"); scanf("%d %d", &rows, &cols); fflush(stdin); } } else showtopic("\n你不能对已有链表初始化\n"); } void destroy(point *head) { point *p; while (head->next) { p = head->next; head->next = p->next; free(p); } } point *found(point head, int oldrows, int oldcols) { point *p; point *q = NULL; for (p = head.next; p && ((p->cols != oldcols) || (p->rows != oldrows)); p = p->next) q = p; return q; //若指定点为第一个,返回值为NULL //若指定点为除了第一个以外的其他节点,则该函数的返回值为目标的前一个指定点。 //若指定点不存在,则该函数的返回值指向末节点。 } void insert(point *head) //采用左插入节点方式 { int newrows; int newcols; int oldrows; int oldcols; point *p; point *pro; showtopic("\n当前坐标如下,请参考插入位置进行左插入\n"); showpoints(*head); showtopic("\n请输入将要插入的位置\n"); scanf("%d %d", &oldrows, &oldcols); fflush(stdin); pro = found(*head, oldrows, oldcols); showtopic("\n请输入你要插入的数据\n"); scanf("%d %d", &newrows, &newcols); fflush(stdin); p = create(newrows, newcols); if (NULL == pro) { pro = head; } p->next = pro->next; pro->next = p; //if (pro == NULL) //新点插入到头结点的后面(原来第一个有效节点前面) //{ // p->next = head->next; // head->next = p; //} //else if (pro->next==NULL) //指定点不存在,应补充在链表的后面。 //{ // p->next = pro->next; // pro->next = p; //} //else //{ // p->next = pro->next; // pro->next = p; //} } void *delete(point *head) { int rows; int cols; point *p; point *pro; showpoints(*head); showtopic("\n请输入你所需要删除节点的rows和cols值\n"); scanf("%d %d", &rows, &cols); fflush(stdin); pro = found(*head, rows, cols); if (pro && pro->next == NULL) //这种表达式,如果前面为假后面直接都不用看了,如果你调换了他两个的条件的位置,会引发一个bug。 { showtopic("\n要删除的节点不存在(按任意键继续....)\n"); getch(); } else { if (NULL == pro) { pro = head; } p = pro->next; pro->next = p->next; free(p); showpoints(*head); showtopic("\n删除成功!!!!(按任意键继续)"); getch(); } return pro; } int main() { int rows; int cols; int input = 0; point pointlinkhead1 = { 0, 0, NULL }; do { system("cls"); printf("\n\n\n"); showtopic("*****张某人的坐标管理系统*****\n\n\n"); showtopic("开始输入坐标-> 1\n"); showtopic("查找坐标-> 2\n"); showtopic("插入坐标-> 3\n"); showtopic("删除坐标-> 4\n"); showtopic("排序坐标-> 5\n"); showtopic("清除数据-> 6\n"); showtopic("退出该系统-> 0\n"); scanf("%d", &input); fflush(stdin); switch (input) { case 1: system("cls"); showtopic("\n请依次录入有效坐标\n\n\n"); initpointlink(&pointlinkhead1); showpoints(pointlinkhead1); showtopic("\n录入成功(按任意键继续)\n"); getch(); break; case 2: system("cls"); showtopic("\n请输入你查找的坐标\n"); scanf("%d %d", &rows, &cols); printf("%s\n", *found(pointlinkhead1, rows, cols)); //暂时无法使用 break; case 3: system("cls"); insert(&pointlinkhead1); showpoints(pointlinkhead1); showtopic("\n插入成功!!!!(按任意键继续)"); getch(); break; case 4: system("cls"); delete(&pointlinkhead1); break; case 5: system("cls"); ordering(pointlinkhead1); showtopic("\n排序成功!!!!!!(按任意键继续....)\n"); showpoints(pointlinkhead1); getch(); break; case 6: system("cls"); destroy(&pointlinkhead1); showtopic("\n清除数据成功!!!!(按任意键继续)"); getch(); break; default: showtopic("输入有误请重新输入\n"); break; } } while (input); return 0; }
相关文章推荐
- 将实体存入到session对象和实现同一功能的jsp页面复用技术——学生管理系统心得体会
- c语言 学生管理系统(数组实现)
- 学生社团管理系统 任务:通过此系统可以实现如下功能(包含但不限于以下功能,可自行设计): 1、社团信息包括:社团编号、社团名称、成立时间…… 2、学生信息包括:学号、姓名、性别、年级、专业…… 3
- C语言实现学生信息管理系统
- C语言实现简单学生管理系统
- linux的学生管理系统——C语言命令行实现
- 学生成绩管理系统课程设计(C语言,链表实现)
- 就C语言的指针、链表的原理和各类操作撰写一篇技术博客,说说自己学习C语言指针和链表的体会,并将学生信息管理系统进行修改,使能完成其他的功能,并撰写体会,附加源代码。
- C语言实现——学生管理系统
- C语言 学生管理系统(结构体实现)
- (C语言) 怎么用代码实现一个学生成绩管理系统
- linux终端版学生信息管理系统【C语言实现】
- 学生信息管理系统简单模拟(C语言实现)
- (一个代码学会c语言操作数据库)linux上通过c语言操作数据库实现基本的学生信息管理系统(增、删、查、改‘显示)
- c语言实现的学生信息管理系统
- C语言实现学生信息管理系统
- C语言实现学生成绩管理系统
- C语言实现学生管理系统
- jsp开发学生信息管理系统,实现了基本的增删改查的功能
- 用C语言关于学生管理系统的几种实现方法(一位数组,二维数组,指针,结构体)