文档介绍:c++数据结构实验报告算法与数据结构;实验报告;实验一:栈与队列;一、实验目的;1、掌握栈和队列特点、逻辑结构和存储结构;2、熟悉对栈和队列的一些基本操作和具体的函数定义;3、利用栈和队列的基本操作完成一定功能的程序;二、实验任务;,利用栈的基本操作;的转换;,并利用队列计;容;,并设计算法与数据结构实验报告实验一:栈与队列一、实验目的 1、掌握栈和队列特点、逻辑结构和存储结构 2、熟悉对栈和队列的一些基本操作和具体的函数定义。 3、利用栈和队列的基本操作完成一定功能的程序。二、实验任务 ,利用栈的基本操作完成十进制数N与其它d进制数的转换。(如N=1357,d=8) ,并利用队列计算并打印杨辉三角的前n行的内容。(n=8) ,并设计程序完成如下功能:读入一个有限大小的整数n,并读入n个数,然后按照与输入次序相反的次序输出各元素的值。三、实验原理 1、将十进制数N转化为d进制时,用除去余数法,用d除N所得余数作为d进制当前个位,将相除所得的商的整数部分作为新的N值重复上述计算,直到N为0为止。将前所得到的各余数反过来连接便得到最终结果。将每次求出的余数入栈,求解结束后,再依次出栈。2、在杨辉三角中可用上一行的数来求出对应位置的下一行的内容。用队列保存上行内容,每当由上行的两个数求出下行的一个数时,其中的前一个便需要删除,而求出的数就入队。为便于求解,在每行的第一个位置添加一个0作为辅助。 3、输出操作应在读入所有输入的整数后才能进行,用栈来存储这些数据,调用入栈出栈函数实现相关功能。四、程序清单第一题#include#ifndefSTACK_H#defineSTACK_Hconstintmaxlen=256;typedefintelementtype;enumerror_code{ess,underflow,overflow};classstack{public:stack();boolempty()const;boolfull()const;error_codeget_top(elementtype&x)const;error_codepush(constelementtypex);error_codepop();private:intcount;elementtypedata;}; stack::stack(){count=0;} boolstack::empty()const{if(count==0)returntrue;returnfalse;} error_codestack::get_top(elementtype&x)const{if(empty())returnunderflow;else{x=data;ess;}} error_codestack::push(constelementtypex){if(full())returnoverflow;data=x;count++; ess;} error_codestack::pop(){ if(empty())returnunderflow;count--;ess;} boolstack::full()const{if(count==maxlen)returntrue;returnfalse;} #endif voidDec_to_Ocx(intN,intd){stackS;intMod,x;while(N!=0){Mod=N%d; 第二题#includeconstintmaxlen=256;typedefintelementtype;enumerror_code{ess,underflow,overflow};classqueue{public:queue();boolempty()const;boolfull()const;error_codeget_front(elementtype&x)const;error_codeappend(constelementtypex);error_codeserve();private:intcount;intfront,rear;elementtypedata;}; queue::queue(){count=0;front=rear=0;}boolqueue::empty()const{if(count==0)returntrue;returnfalse;} boolqueue::full()const{if(count==maxlen-1)returntrue;returnfalse; (Mod);N=N/d;} while(!()