1 / 15
文档名称:

数据结构与算法的实验心得.docx

格式:docx   大小:20KB   页数:15页
下载后只包含 1 个 DOCX 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

数据结构与算法的实验心得.docx

上传人:feng1964101 2019/2/21 文件大小:20 KB

下载得到文件列表

数据结构与算法的实验心得.docx

文档介绍

文档介绍:数据结构与算法的实验心得算法与数据结构实验报告学院:计算机与信息学院专业班级: 姓名: 学号: 实验一栈和队列实验目的: 掌握栈和队列特点、逻辑结构和存储结构熟悉对栈和队列的一些基本操作和具体的函数定义。利用栈和队列的基本操作完成一定功能的程序。实验任务: ,利用栈的基本操作完成十进制数N与其它d进制数的转换。实验原理: 将十进制数N转换为八进制时,采用的是“除取余数法”,即每次用8除N所得的余数作为八进制数的当前个位,将相除所得的商的整数部分作为新的N值重复上述计算,直到N为0为止。此时,将前面所得到的各余数反过来连接便得到最后的转换结果。程序清单: #include #include usingnamespacestd; typedefintDATA_TYPE; constintMAXLEN=100; enumerror_code { ess,overflow,underflow }; classstack { public: stack(); boolempty()const; error_codeget_top(DATA_TYPE&x)const; error_codepush(constDATA_TYPEx); error_codepop(); boolfull()const; private: DATA_TYPEdata[MAXLEN]; intcount; }; stack::stack() { count=0; } boolstack::empty()const { returncount==0; } error_codestack::get_top(DATA_TYPE&x)const if(empty()) returnunderflow; else { x=data[count-1]; ess; } } error_codestack::push(constDATA_TYPEx) { if(full()) returnoverflow; else { data[count]=x; count++; } } error_codestack::pop() { if(empty()) returnunderflow; else { count--; ess; } } boolstack::full()const { returncount==MAXLEN; } voidmain() { stackS; intN,d; cout>N>>d; if(N==0) { cout #include usingnamespacestd; typedefintDATA_TYPE; constintMAXLEN=100; enumerror_code { ess,underflow,overflow }; classqueue { public: queue(); boolempty()const; error_codeget_front(DATA_TYPE&x)const;error_codeappend(constDATA_TYPEx);error_codeserve(); boolfull()const; private: intfront,rear; DATA_TYPEdata[MAXLEN]; }; queue::queue() { rear=0; front=0; } boolqueue::empty()const { return(front%MAXLEN==rear%MAXLEN); } error_codequeue::get_front(DATA_TYPE&x)const{ if(empty()) returnunderflow; else { x=data[front%MAXLEN]; ess; } } error_codequeue::append(constDATA_TYPEx){ if(full()) returnoverflow; else { data[rear%MAXLEN]=x; rear++; } } error_codequeue::serve() { if(empty()) returnunderflow; else { f(转载于:写论文网:数据结构与算法的实验心得)ront++; ess; } } boolqueue::full()const { return((rear+1)%MAXLEN==front);}voidmain() { queueQ; intnum1,num2; inti=0; cout //N代表可以改动数组的元素个数#defineN5//函数功能:用于判断一个数组序列是否为一个非递减序列; boolSorted(inta[],int