数据结构课程设计回文判断

上传人:ali****an 文档编号:118771424 上传时间:2019-12-25 格式:DOCX 页数:14 大小:136.54KB
返回 下载 相关 举报
数据结构课程设计回文判断_第1页
第1页 / 共14页
数据结构课程设计回文判断_第2页
第2页 / 共14页
数据结构课程设计回文判断_第3页
第3页 / 共14页
数据结构课程设计回文判断_第4页
第4页 / 共14页
数据结构课程设计回文判断_第5页
第5页 / 共14页
点击查看更多>>
资源描述

《数据结构课程设计回文判断》由会员分享,可在线阅读,更多相关《数据结构课程设计回文判断(14页珍藏版)》请在金锄头文库上搜索。

1、设计题目:3.4.4 回文判断专业:*姓名:*学号:*日期:2011.09.11一, 问题描述二, 需求分析三, 概要设计四, 详细设计五, 测试分析六, 源程序清单七, 用户使用手册八, 心得体会一、问题描述判断依次读入的一个以为结束符的字母序列,是否形如“序列1&序列2”模式的字符序列。其中序列1和序列2都不含“&”字符,且序列2是序列1的逆序列。二、需求分析(1)输入测试数据组数,接着分组输入字符串,以结尾。(2)输入序列总长不超过 (MAX_N = 10005)/2 个。将序列1先入栈,接着处理序列2,同时出栈判断。(3)将序列1全部入栈,接着输入序列2,同时出栈判断。(4)如果序列满

2、足题目要求,则输出“回文序列”;否则,输出“非回文序列”。(5)测试数据:pal.txt12a+b&b+aa&ba&a & & & &ab&baabc&bcbc&cba&abab&三、概要设计(1)数据结构:typedef struct Stackint top,size;char strMAX_N1;使用结构体,内部定义数组模拟栈。top为栈顶指针,指向当前元素的下一个位置,size表示栈内的元素个数。(2)函数介绍:void st_init(Stack *st);/栈的初始化bool st_push(Stack *st,const char *temp);/入栈bool st_top(St

3、ack *st,char *temp);/出栈(3)程序流程图:stri=?开始读入字符,stri+iNstrlen(str)=奇数Y对序列2进行判断,同时出栈处理,标记判断状态。序列1入栈flagYN非回文序列回文序列结束四、详细设计 主要出栈和入栈函数,可以对边界进行处理,防止栈为空情况。bool st_push(Stack *st,const char *temp)if( st-topst-size )return false;st-strst-top+ = *temp;return true;bool st_pop(Stack *st)if( st-top=0 )return fals

4、e;st-top-;return true;另外还有取栈顶函数。bool st_top(Stack *st,char *temp)if( st-top=0 )return false;*temp = st-strst-top-1;return true;五、测试分析(1)测试环境:CodeBlock 10.04(2)输入过程:因为使用 getchar() 输入,所以有些地方需要谨慎处理。用于getchar() 可以读入任意字符,所以回车和空格之类的特殊字符也作为序列参与判断了。(3)测试结果:六、源程序清单#include #include #include const int MAX_N =

5、 10005;typedef struct Stackint top,size;char strMAX_N1;void st_init(Stack *st)st-size=MAX_N1;st-top=0;bool st_push(Stack *st,const char *temp)if( st-topst-size )return false;st-strst-top+ = *temp;return true;bool st_pop(Stack *st)if( st-top=0 )return false;st-top-;return true;bool st_top(Stack *st,c

6、har *temp)if( st-top=0 )return false;*temp = st-strst-top-1;return true;int main()char strMAX_N,c;int i,j,cas,len;Stack st;bool flag;/freopen(pal.txt,r,stdin);printf(请输入测试组数:n);scanf(%d,&cas);getchar();j=0;while( cas- ) +j; printf(n第 %d 组数据n,j);printf(n请输入数据(字符串1&字符串2):n);for( i=0; 1; i+ )stri=getch

7、ar();if( stri= )stri=0;break;getchar();flag = true;len = strlen(str);st_init(&st);if( !len&1 )flag = false;elsefor( i=0; ilen; i+ )if( stri=& )break;st_push(&st,&stri);for( +i; i0 )flag = false;printf(nCase : %dn,j);if( flag )printf(回文序列。n);elseprintf(非回文序列。n);printf(n);printf(输入结束。By changning.huang);/while( true );return 0;七、用户使用手册(1)开始需要输入要测试的组数,这样方便结束,减少一些繁琐的结束判断。(2)因为定义了文件流,可以用文件方便的进行读写。如使用文件读写,稍微将以下语句注释掉:printf(请输入测试组数:n);printf(n第 %d 组数据n,j);printf(n请输入数据(字符串1&字符串2):n);当然,不需要的话,注释掉 freopen(pal.txt,r,stdin); 即可。(3)输入格式依照题目要求即可。14

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 高等教育 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号