queue类的实现与stack的实现

上传人:第*** 文档编号:32817839 上传时间:2018-02-12 格式:DOC 页数:4 大小:40.50KB
返回 下载 相关 举报
queue类的实现与stack的实现_第1页
第1页 / 共4页
queue类的实现与stack的实现_第2页
第2页 / 共4页
queue类的实现与stack的实现_第3页
第3页 / 共4页
queue类的实现与stack的实现_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《queue类的实现与stack的实现》由会员分享,可在线阅读,更多相关《queue类的实现与stack的实现(4页珍藏版)》请在金锄头文库上搜索。

1、/包括queue类的实现及杨辉三角的输出#include#include#includeusing namespace std;template class queueprotected:struct nodeT data;node *next;public:node(T value,node* link)data=value;this-next=link-next;link-next=this;node(T value)data=value;private:node *last;public:queue(T value)last=new node(value);last-next=last;

2、queue()while(last!=last-next) pop();free(last);queue(queue &ori)node *p1=new node(1),*p2=ori.last;p1-data=p2-data;last=p1; while(p2-next!=ori.last)p2=p2-next;p1=new node(p2-data,p1);p1-next=last;p1=last;void push(T value)last=new node(value,last);void pop()if(last=NULL) coutnext;if(last-next=last) l

3、ast=NULL;else last-next=last-next-next;free(p);T front()return last-next-data;bool empty()if(last=NULL) return true;return false;void yhui(int n)queueque(1); que.push(1);coutn) yhui(n);return 0;/以下是 Stack 的实现代码#ifndef STACK_H#define STACK_H#include /精简版#include#include #includeusing namespace std;te

4、mplate class Stackprotected:struct nodeT data;node *next,*last;node(T item,node*ptr)data=item;ptr-next=this;this-last=ptr;node(T item) data=item; ;private:node *head;int size;public:Stack()head=NULL;size=0; Stack()while(size-)node *del=head;head=head-last;free(del);bool empty() return size=0?true:false;void push(T value)head=(+size)=1?new node(value):new node(value,head);void pop()if(size=0)coutlast;free(del);size-;T ;#endif

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 建筑/环境 > 工程造价

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