ImageVerifierCode 换一换
格式:DOCX , 页数:24 ,大小:136.91KB ,
资源ID:8132550      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/8132550.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(课题数据结构课程设计报告书.docx)为本站会员(b****5)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

课题数据结构课程设计报告书.docx

1、课题数据结构课程设计报告书北方民族大学课程设计课程名称:数据结构与算法课程设计院(部)名 称: 信息与计算科学学院组长姓名: 金龙龙 20080544同组人员姓名: 任杰 马鹏起 赵俞军 20080576赵庆康 20080570设 计 时 间:2015.6.1-2015.6.24金龙龙 200805442、 一元多项式计算任务:能够按照指数降序排列建立并输出多项式;能够完成两个多项式的相加、相减,并将结果输入;在上交资料中请写明:存储结构、多项式相加的基本过程的算法(可以使用程序流程图) 、源程序、测试数据和结果、算法的时间复杂度、另外可以提出算法的改进方法;存储结构:链表存储#include

2、#include#include#define null 0typedefstructpolynodeintcoef;int exp;structpolynode *next;node;node *create() node *h,*r,*s;intc,e; h=(node*)malloc(sizeof(node); r=h;printf(coef:);scanf(%d,&c);printf(exp: );scanf(%d,&e); while(c!=0) s=(node*)malloc(sizeof(node); s-coef=c; s-exp=e; r-next=s; r=s;printf

3、(coef:);scanf(%d,&c);printf(exp: );scanf(%d,&e); r-next=NULL; return(h);void arrange(node *pa) node *h=pa,*p,*q,*r; for(p=pa;p-next!=NULL;p=p-next); r=p; for(h=pa;h-next!=r;) for(p=h;p-next!=r&p!=r;p=p-next) if(p-next)-exp(p-next-next)-exp) q=p-next-next; p-next-next=q-next; q-next=p-next; p-next=q;

4、 r=p; void neipai(node *head) node *p,*q,*r,*Q; p=head; if(head-next-next!=NULL) for(q=p-next;q!=NULL;q=q-next) for(p=q-next,r=q;p!=NULL;) if(q-exp=p-exp) q-coef=q-coef+p-coef; r-next=p-next; Q=p;p=p-next; free(Q); else r=r-next; p=p-next; void insert(node *head,node *s) node *pre,*p; pre=head; p=pr

5、e-next; while(p!=NULL) if(p-exp s-exp) break; pre=p; p=p-next; s-next=p; pre-next=s; node *copyList(node *head) node *l = NULL, *newHead;newHead = (node *) malloc(sizeof(node);newHead-next = NULL; head = head-next; while (head != NULL) l = (node *) malloc(sizeof(node); l-coef = head-coef; l-exp = he

6、ad-exp; insert(newHead, l); head = head-next; return newHead;void print(node *p) while(p-next!=NULL) p=p-next;printf( %d*x%d,p-coef,p-exp); void polyadd(node *ha, node *hb) node *p,*q,*pre,*temp;int sum; p=ha-next; q=hb-next; pre=ha; while(p!=NULL&q!=NULL) if(p-exp=q-exp) sum=p-coef+q-coef; if(sum!=

7、0) p-coef=sum; pre-next=p;pre=pre-next;p=p-next; temp=q;q=q-next;free(temp); else temp=p-next;free(p);p=temp; temp=q-next;free(q);q=temp; else if(p-expexp) pre-next=p; pre=pre-next; p=p-next; else pre-next=q; pre=pre-next; q=q-next; if(p!=NULL) pre-next=p; else pre-next=q; void polysub(node *ha,node

8、 *hb) node *p,*q,*pre,*temp,*x;int sum; p=ha-next; q=hb-next; x=q; pre=ha; while(x!=null) x-coef=-x-coef; x=x-next; while(p!=NULL&q!=NULL) if(p-exp=q-exp) sum=p-coef+q-coef; if(sum!=0) p-coef=sum; pre-next=p;pre=pre-next;p=p-next; temp=q;q=q-next;free(temp); else temp=p-next;free(p);p=temp; temp=q-n

9、ext;free(q);q=temp; else if(p-expexp) pre-next=p; pre=pre-next; p=p-next; else pre-next=q; pre=pre-next; q=q-next; if(p!=NULL) pre-next=p; else pre-next=q;void main() node *ha,*hb,*hc,*hd;printf(please input the coef and exp of ha:n); ha=create(); arrange(ha);neipai(ha);hc=copyList(ha); print(ha);pr

10、intf(n);printf(please input the coef and exp of hb:n);hb=create(); arrange(hb);neipai(hb);hd=copyList(hb); print(hb);printf(n);printf(add is :n);polyadd(ha,hb); print(ha);printf(n);printf(sub is :n);polysub(hc,hd); print(hc);运行结果赵俞军 200805767、 猴子选大王任务:一堆猴子都有编号,编号是1,2,3 .m ,这群猴子(m个)按照1-m的顺序围坐一圈,从第1开始

11、数,每数到第N个,该猴子就要离开此圈,这样依次下来,直到圈中只剩下最后一只猴子,则该猴子为大王。要求:输入数据:输入m,nm,n 为整数,nm输出形式:中文提示按照m个猴子,数n 个数的方法,输出为大王的猴子是几号 ,建立一个函数来实现此功能 #include #include typedefstruct monkey int num; struct monkey *next; Monkey,*LINK; void main() LINK p,head,p2; inti,m,n;printf(Input m:n);scanf(%d,&m);printf(Input n(nm):n);scanf

12、(%d,&n);head=p=p2=(LINK)malloc(sizeof(Monkey); /三个指针指向同一个内存单元for(i=1;inext=p; p2=p; p2-next=head; /把链表的首尾相连p=head; /p指向了第一个结点printf(put the sorted number to the monkey!n); /对猴子进行编号for(i=1;inum=i; /从第一个结点到最后一个结点一次给猴子编号printf( the %d monkey:%dn,p-num,p-num); p=p-next; /循环结束,p指向了最后一个结点i=0; p=head; /再把p

13、指向第一个结点while(1) i+; printf( the %d number monkey shouted out:%dn,p-num,i);/这只猴子报号if(p-next=p) break; /此为while循环的出口if(i=n) /if语句中是删除结点的过程 i=0; printf( the %d number monkey is out the circlen,p-num); /这只猴子被淘汰printf(n); p2-next=p-next; /在此删除结点pp=p2-next; continue; else if(i=n-1) p2=p; /保存将要退出结点的前一个结点(存

14、到p2中)p=p-next; printf( the monkey is the winner :%d,p-num); /这只猴子胜出运行结果:马鹏起 200805968. 建立二叉树,后序、先序遍历( 用递归或非递归的方法都可以)任务:要求能够输入树的各个结点,并能够输出用不同方法遍历的遍历序列;分别建立二叉树存储结构的输入函数、输出后序遍历序列的函数、输出先序遍历序列的函数;# include# include# define bitreptrstruct type1 /*二叉树及其先序边历*/# define null 0# define lensizeof(bitreptr)bitre

15、ptr *bt;intf,g,n;bitreptr /*二叉树结点类型说明*/ char data;bitreptr *lchild,*rchild; ;preorder(bitreptr *bt) /*先序遍历二叉树*/ if(g=1) printf(先序遍历序列为:n); g=g+1; if(bt) printf(%6c,bt-data); preorder(bt-lchild); preorder(bt-rchild); else if(g=2) printf(空树n); bitreptr *crt_bt() /*建立二叉树*/ bitreptr *bt; char ch; if(f=1

16、) printf(输入根结点,#表示结束n); else printf(输入结点,#表示结束n);scanf(n%c,&ch); f=f+1; if(ch=#) bt=null; else bt=(bitreptr *)malloc(len);bt-data=ch;printf(%c 左孩子,bt-data);bt-lchild=crt_bt();printf(%c 右孩子,bt-data);bt-rchild=crt_bt(); return(bt);postorder(bitreptr *bt) /*后序遍历*/ if(n=1) printf(后序遍历序列为:n); n=n+1; if(b

17、t) postorder(bt-lchild);postorder(bt-rchild);printf(%6c,bt-data); else if(n=2) printf(空树n); main()f=1; g=1; n=1;bt=crt_bt(); preorder(bt);printf(n);postorder(bt);printf(n); 运行结果:任杰 200805356、 joseph环 任务:编号是1,2,,n的n个人按照顺时针方向围坐一圈,每个人只有一个密码(正整数)。一开始任选一个正整数作为报数上限值m,从第一个人开始顺时针方向自1开始顺序报数,报到m时停止报数。报m的人出列,将

18、他的密码作为新的m值,从他在顺时针方向的下一个人开始重新从1报数,如此下去,直到所有人全部出列为止。设计一个程序来求出出列顺序。要求:利用单向循环链表存储结构模拟此过程,按照出列的顺序输出各个人的编号。测试数据:m的初值为20,n=7 ,7个人的密码依次为3,1,7,2,4,7,4,首先m=6,则正确的输出是什么?要求:输入数据:建立输入处理输入数据,输入m的初值,n ,输入每个人的密码,建立单循环链表。输出形式:建立一个输出函数,将正确的输出序列#include #include #include #include /* 结构体和函数声明 */typedefstruct _node_tint

19、n_num;struct _node_t *next; node_t;node_t *node_t_create(int n);node_t *node_t_get(node_t *pn, int m);/* 功能函数实现 */* * name: node_t_create * params: * n in 输入要构造的链表的个数 * return: * 返回构造成功的环形单向链表指针 * notes: * 构造节点数量为 n 的环形单向链表 * */node_t * node_t_create(int n)node_t *p_ret = NULL; if (0 != n) intn_idx

20、= 1;node_t *p_node = NULL; /* 构造 n 个 node_t */p_node = (node_t *) malloc(n * sizeof(node_t); if (NULL = p_node) return NULL; elsememset(p_node, 0, n * sizeof(node_t); /* 内存空间申请成功 */p_ret = p_node; for (; n_idx n_num = n_idx;p_node-next = p_node + 1;p_node = p_node-next; p_node-n_num = n;p_node-next

21、= p_ret; return p_ret;/* * name: main * params: * none * return: * int * notes: * main function */int main()int n, m;node_t *p_list, *p_iter;printf(input m:n);scanf(%d,&m);printf(input n:n);scanf(%d,&n); /* 构造环形单向链表 */p_list = node_t_create(n); /* Josephus 循环取数 */p_iter = p_list; m %= n; while (p_it

22、er != p_iter-next) inti = 1; /* 取到第 m-1 个节点 */ for (; i next; /* 输出第 m 个节点的值 */printf(%dn, p_iter-next-n_num); /* 从链表中删除第 m 个节点 */p_iter-next = p_iter-next-next;p_iter = p_iter-next; printf(%dn, p_iter-n_num); /* 释放申请的空间 */ free(p_list);运行结果:赵庆康 200805709、 赫夫曼树的建立 任务 :建立建立最优二叉树函数要求:可以建立函数输入二叉树,并输出其赫

23、夫曼树在上交资料中请写明:存储结构、 基本算法(可以使用程序流程图) 、输入输出、源程序、测试数据和结果、算法的时间复杂度、另外可以提出算法的改进方法;#include#include#include#define LEN sizeof(structHTnode)inti,l,n,w=0,c,start,a1,a2,f;structHTnode unsigned int weight; unsigned intparent,lchild,rchild; *p,*HT;typedef char *Huffmancode;Huffmancode HC;char *cd;select()int k=

24、1,j,flag=0; while(HT+k)-parent!=0) k+; for(j=k+1;jparent!=0) flag=1; if(HT+j)-weight=0) flag=1; if(!flag) if(HT+j)-weightweight) k=j; return(k);main()printf(n赫夫曼树的建立:n);printf(请输入权值(叶子)数目:);scanf(%d,&l); while(l1) printf(输入错误,请重新输入权值数目:); scanf(%d,&l); if(l=1) printf(n只有一个权值,无须建立赫夫曼树!); else n=2*l-1

25、; HT=(structHTnode*)malloc(n+1)*LEN);printf(请按对应顺序输入权值(输入一权值,键入一回车):n); for(i=1,p=HT+1;i=l;+i,+p) scanf(%d,&w); while(wweight=w; p-parent=0; p-lchild=0; p-rchild=0; for(i=l+1;iweight=0; p-parent=0; p-lchild=0; for(i=l+1;iparent=i; a2=select(); (HT+a2)-parent=i; (HT+i)-lchild=a1; (HT+i)-rchild=a2; (H

26、T+i)-weight=(HT+a1)-weight+(HT+a2)-weight; HC=(Huffmancode)malloc(l+1)*sizeof(char *);cd=(char *)malloc(l*sizeof(char); *(cd+(l-1)=0; for(i=1;iparent;f!=0;c=f,f=(HT+f)-parent) if(HT+f)-lchild=c) *(cd+(-start)=0; else *(cd+(-start)=1; *(HC+i)=(char *)malloc(l-start)*sizeof(char);strcpy(*(HC+i),(cd+start); printf(n对应的二进制赫夫曼编码为:n

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1