实验数据结构栈和队列的实现和应用.docVIP

  • 6
  • 0
  • 约9.61千字
  • 约 14页
  • 2018-06-06 发布于江西
  • 举报

实验数据结构栈和队列的实现和应用.doc

实验数据结构栈和队列的实现和应用.doc

实验1 栈和队列的?实现和应用? 实验目的 1.熟练掌握栈?、队列的建立?方法; 2.熟练掌握栈?和队列基本?操作; 3.栈和队列的?实例应用 。 实验内容 1.选用一种存?储结构建立?栈、队列 2.栈的应用:A desk calcu?latio?n(教科书P6?6) 3.队列验证:Menu-drive?n demon?strat?ion(教科书上P?93) 实验结果 总结算法应?用和结构优?缺点 栈: #inclu?de iostr?eam using? names?pace std; const? int maxst?ack = 100; enum Error?_code? {succe?ss = 1, overf?low = -1, under?flow = -1}; typed?ef int Stack?_entr?y; class? Stack? { publi?c: Stack?() { count? = 0; } bool empty?(); Error?_code? pop(); Error?_code? top(Stack?_entr?yitem); Error?_code? push(const? Stack?_entr?y item); int size(); priva?te: int count?; Stack?_entr?y entry?[maxst?ack]; }; Error?_code? Stack?::push(const? Stack?_entr?y item) { Error?_code? outco?me = succe?ss; if(count? = maxst?ack) { outco?me = overf?low; } else { entry?[count?++] =item; } retur?n outco?me; } Error?_code? Stack?::pop() { Error?_code? outco?me = succe?ss; if(count? == maxst?ack) { outco?me = under?flow; } else { count?--; } retur?n outco?me; } Error?_code? Stack?::top(Stack?_entr?y item) { Error?_code? outco?me = succe?ss; if(count? == 0) { outco?me = under?flow; } else { item = entry?[count?-1]; } retur?n outco?me; } bool Stack?::empty?() { bool outco?me = true; if(count? 0) { outco?me = false?; } retur?n outco?me; } int Stack?::size() { retur?n count?; } int main() { Stack? numbe?rs; for(int i = 0; i 10; i++) { numbe?rs.push(i); } int v; while?(!numbe?rs.empty?()) { numbe?rs.top(v); coutvendl; numbe?rs.pop(); } retur?n 0; } 队列: #inclu?de iostr?eam using? names?pace std; const? int maxqu?eue = 100; enum Error?_code? {succe?ss = 1, overf?low = -1, under?flow = -1}; typed?ef int Queue?_entr?y; class? Queue? { publi?c: Queue?() { count? = 0; rear = maxqu?eu

文档评论(0)

1亿VIP精品文档

相关文档