您好,欢迎光临本网站![请登录][注册会员]  
文件名称: 数据结构栈的实现
  所属分类: 其它
  开发工具:
  文件大小: 90kb
  下载次数: 0
  上传时间: 2011-12-24
  提 供 者: yangbu******
 详细说明: 实验目的 1.掌握栈、思想及其存储实现。 2.掌握栈、常见算法的程序实现。 实验原理 1. 根据实验内容编程,上机调试、得出正确的运行程序。 实验仪器 计算机及C++编译软件 实验步骤 1. 编译运行程序,观察运行情况和输出结果。 2. 写出实验报告(包括源程序和运行结果)。 实验内容 \1.采用链式存储实现栈的初始化、入栈、出栈操作 CODE: #include template class link { public: T date; link *next; link(const T info, link *nextvalue=NULL) { date=info; next=nextvalue; } link(link *nextvalue) { next=nextvalue; } }; template class inkstack { private: link *top; int size; public: inkstack(); ~inkstack(); void clear(); bool push(const T item); bool pop(T & item); bool toop(T & item); }; template inkstack::inkstack() { top=NULL; size=0; } template inkstack::~inkstack() { clear(); } template void inkstack::clear() { while(top!=NULL) { link *tmp=top; top=top->next; delete top; } size=0; } template bool inkstack::push(const T item) { link *tmp=new link(item,top); top=tmp; size++; return true; } template bool inkstack::pop(T & item) { link *tmp; if(size==0) { cout<<"栈为空,不能执行出栈操作"<date; tmp=top->next; delete top; top=tmp; size--; return true; } template bool inkstack::toop(T & item) { if(size==0) { cout<<"栈为空,不能执行出栈操作"<date; return true; } void main() { inkstack b; int i,a[10],c,d; for(i=0;i<5;i++) { cin>>a[i]; b.push(a[i]); } for(i=0;i<5;i++) { b.pop(c); cout< using namespace std; class sqstack { private: int top; int maxsize; int *elem; public: sqstack(int size) {maxsize=size; elem=new int[maxsize]; top=0; } ~sqstack(){delete []elem;} int length(); bool empty(){return top==0;} void push(int e); void pop(int &e); void display(); }; int sqstack::length() { return top; } void sqstack::push(int e) { elem[top++]=e; } void sqstack::pop(int &e) { if (!empty()) {e=elem[--top]; ; } } void sqstack::display() { for(int i=top-1;i>=0;i-- ) { cout<>x; for(i=1;i<=x;i++) {cout<<"请输入要入栈的"<>e; a.push (e); } cout<<"显示队栈中的元素为:"<>x; cout<<"出栈元素为:"; for(i=1;i<=x;i++) {a.pop (e); cout<
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: 数据结构栈的实现
 输入关键字,在本站1000多万海量源码库中尽情搜索: