猴子选大王——课程设计
- 格式:doc
- 大小:255.50 KB
- 文档页数:20
邮电与信息工程学院
课程设计说明书
课题名称:猴子选大王
学生学号:
专业班级:
学生姓名:
学生成绩:
指导教师:
课题工作时间:2010-6-22至2010-6-25
目录
摘要............................................................................................, (6)
Abstract ......................................................................................, (7)
第一章课题背景.................................................................................,.. (8)
1.1课程设计的目的 (8)
1.2 课程设计的要求.............................................................................., (8)
1.3 课程设计的实验环境......................................................................,. (8)
第二章课程设计详细内容...................................................................,, (9)
2.1 问题描述......................................................................................,, (9)
2.2 程序代码精解.................................................................................,, (9)
2.3 程序结果运行...............................................................................,. (13)
总结......................................................................................., (15)
致谢.........................................................................................,.. (16)
参考文献.....................................................................................,.. (17)
附录主要程序代码....................................................................., (18)
摘要
本次程序程序设计的主要目的是解决变相的“约瑟夫环”问题---猴子选大王。从而使复杂的选举工作变得明朗化。
全程序以数据结构(C语言)中的循环单链表为主要的设计支柱,利用了C语言简洁紧凑、灵活方便,语法限制不太严格,程序设计自由度大,生成目标代码质量高,程序执行效率高等方面的优点。循环单链表是单链表的另一种形式,其结构特点是链表中最后一个结点的指针域不再是结束标记,而是指向整个链表的第一个结点,从而使链表形成一个环,基于这样的特点,它适合处理具有环形结构的数据元素序列。
在程序代码的编写中,运用了结构体类型(struct Node),动态申请内存空间函数malloc(),释放动态申请内存空间函数free()等类型,同时也具有多种循环、条件语句控制程序流向,如:嵌套if else语句,多重for循环语句,还有链表中结点指针(p->next),从而使程序完全结构化。这样编写出的完整程序代码可以实现“猴子选大王”功能,输入猴子的数目m,循环数n,对m个猴子进行编号,通过嵌套if else语句,for 语句,一遍一遍的循环,判断,删除,直到只剩下最后一个猴子,即大王。这样就可以实现所需的基本功能了。
关键词:数据结构;循环;单链表
Abstract
The main purpose of the program design process to solve the form of "Joseph Ring" in the election --- monkey king. So complex it became clear the election.
All procedures for data structures (C language) in single-cycle design of the main pillars of the list, using the C language simple and compact, flexible and convenient, the syntax is not strictly limited, program design flexibility to produce high quality object code, program execution the advantages of higher efficiency. Single-loop single-linked list is another form of list, its structural features is the last node list pointer field is no longer the end of the tag, but point to the list the first node, so that form a ring list, based on Such features, it has a ring structure for the data processing sequence of elements.
The preparation of the program code, the use of a structure type (struct Node), dynamic application memory function malloc (), the release of dynamic memory functions for free () and other types, but also with a variety of loop, conditional statements control program flow such as: nested if else statements, multiple for loop, there is a linked list node pointer (p-> next), to make the program fully structured.
Write such a complete program code can have a "monkey king selected" feature, enter the number of monkeys m, cycles n, m were monkeys on the number, by nested if else statements, for statement, the cycle over and over again, judge, removed until there are only a monkey, or king. This can achieve the required basic function.
Keywords: data structures; circulation; single linked list