2n数排序(C++顺序栈和循环队列实现).docx_第1页
2n数排序(C++顺序栈和循环队列实现).docx_第2页
2n数排序(C++顺序栈和循环队列实现).docx_第3页
2n数排序(C++顺序栈和循环队列实现).docx_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

/第一个头文件:Seqstack.h#ifndef SEQSTACK_H#define SEQSTACK_H#include using namespace std;const int maxsize=100;template class Seqstacktemplate friend ostream &operator(ostream &,const Seqstack &);public:Seqstack();Seqstack(T a,int n);void push(T i);T pop();Seqstack()private:T datamaxsize;int top;template ostream &operator(ostream &os,const Seqstack &s)for(int i=s.top;i=0;i-)oss.datait;osendl;return os;template Seqstack:Seqstack()top=-1;template Seqstack:Seqstack(T a,int n)top=-1;for(int i=0;in;i+)top+;datai=ai;cout栈的数据初始状态为:n;template void Seqstack:push(T i)if(topmaxsize-1)cout数组溢出!n;top+;datatop=i;template T Seqstack:pop()if(top=-1)cout数组已空!n;int x=datatop;top-;return x;#endif/第二个头文件:Linkqueue.h#ifndef LINKQUEUE_H#define LINKQUEUE_H#include using namespace std;const int queuesize=100;template class Linkqueuepublic:Linkqueue();void entry(T i);T out();int getf();Linkqueue()private:int first;int rear;T dataqueuesize;template Linkqueue:Linkqueue()first=rear=0;template void Linkqueue:entry(T i)if(rear+1)%queuesize=first)cout数组溢出!n;rear=(rear+1)%queuesize;datarear=i;template T Linkqueue:out()if(first=rear)cout数组溢出!n;/这里有个问题,我要再调试看看,先注释掉first=(first+1)%queuesize;return datafirst;template int Linkqueue:getf()return first;#endif/第三个头文件:Function.h#ifndef FUNCTION_H#define FUNTION_H#include #include Linkqueue.h#include Seqstack.husing namespace std;template void fun(Seqstack &s,Linkqueue &l,int &n)for(int i=0;in;i+)l.entry(s.pop();/栈内元素全部出栈 &入队for(int i=0;in;i+)if(l.getf()%2=0)l.entry(l.out();/偶数号先出队&入队else s.push(l.out();/奇数号入栈for(int i=0;i(n/2);i+)l.entry(s.pop();/栈内元素全部出栈&入队for(int i=0;i(n/2);i+)s.push(l.out();/队列前一半偶数号全部出队&入栈for(int i=0;i(n/2);i+)l.entry(s.pop();/栈内元素全部出栈&入队for(int i=0;in;i+)s.push(l.out();/队列所以元素出对&全部入栈cout栈经排序后状态为:n;#endif/主源文件;#include #include Function.husing namespace std;int main(void)int a16=1,2,3,4,5,6,7,8,9,10,11,12,13,14,15

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论