数据结构报数出列游戏源代码
这是我们数据结构的一个课程设计,要求高手用Codeblocks软件哦,还要有头文件,可执行文件以及主函数三部分!!!
很简单的单链表处理, 我建议你自己好好做做 将来工作链表是重要数据结构之一,使用的地方非常多 一定要自己做做 既然如此,给你代码: 另外codeblock不好用,建议你使用netbeans,代码导航功能强大 #include #include //最多人数 #define MAXNUMBER 12 //每一个人最大的数m #define MAX_M 100 typedef struct Person_s * PPerson; struct Person_s { int no; //人员编号 int number; //持有的数据 PPerson next; //下一个链节点 }; typedef struct Person_s Person; /** * 获取每一个人的m值,获取的值是1-max_m * @param max_m * @return a */ int gen_m(int max_m) { int m = rand(); while ((m max_m)) { m = rand(); } return m; } /** * 初始化人员信息 * @param persons 人数 * @param head 链表头,链表头中的number是表中的当前人数 * @return 0 成功 1 失败 */ int initPerson(int persons, PPerson head) { int i; PPerson person; if (head == NULL) { printf("没有初始化头节点\n"); return 1; } //初始化头节点 head->number = 0; head->next = NULL; head->no = 0; printf("现在开始生成 %d 个人信息:\n", persons); for (i = 0; i no = (i + 1); //人员编号 person->number = gen_m(MAX_M); //持有的M //加入到链表中 person->next = head->next; head->next = person; head->number++; } return 0; } /** * 释放链表空间,注意不释放头节点 * @param head 头节点 * @return */ int destroyPerson(PPerson head) { PPerson person; if (head == NULL) { return 0; } while (head->next != NULL) { person = head->next; head->next = person->next; head->number--; free(person); } } /** * 把人员信息全部打印出来 * @param head */ void printPerson(PPerson head) { PPerson person; if ((head == NULL) || (head->next == NULL)) { printf("给定的链表是空表\n"); return; } person = head->next; while (person != NULL) { printf("人 %d 持有的 m 是:%d\n", person->no, person->number); person = person->next; } } /** * 完成处理 * @param head 链表头 * @param init_m 开始的m */ void chang(PPerson head, int init_m) { PPerson person; PPerson p1; if ((head == NULL) || (head->next == NULL) || (head->number == 0) || (init_m MAX_M)) { printf("没有可以使用的人员信息,或者初始的m有问题\n"); return; } p1 = head->next; while (1) { if (head->number 0)) { p1 = person; person = person->next; init_m--; } //到队尾了 if (person == NULL) { //回到第一个 p1 = head->next; continue; } //数到了0 if (init_m == 0) { //去掉那个人 //首先判断是不是第一个节点 if (person == head->next) { head->next = person->next; }else{ p1->next = person->next; } p1 = person->next; head->number--; init_m = person->number; printf("人 %d 离开了,新的m是: %d\n", person->no, init_m); free(person); continue; } } } /** * 主程序 * @return */ int main() { PPerson head; int init_m; //初始化链表头 head = (PPerson) malloc(sizeof (Person)); //初始化人员信息 if (initPerson(MAXNUMBER, head) != 0) { printf("初始化人员信息失败。
\n"); destroyPerson(head); return 1; } //打印人员信息 printPerson(head); //获取第一个m值 init_m = gen_m(MAX_M); //开始处理 chang(head, init_m); //释放人员信息 destroyPerson(head); //释放头节点 free(head); return 0; }。
答:入门:可以看谭浩强的《C语言程序设计教程》 搞单片机开发这本书还不够,可以买单片机C语言设计之类的书。 搞软件 看孙兴的C++深入详解详情>>
问:C语言C语言为了准备三级网络技术上机考试,c语言至少要看到那一章节?
答:数据类型、输入输出、选择语句、循环语句、数组、指针、函数、文件详情>>
答:c++ 是程序语言 不是系统 谢谢详情>>