1 / 16
文档名称:

数据结构--队列实现舞伴配对问题 (舞伴程序 c ).doc

格式:doc   大小:63KB   页数:16页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

数据结构--队列实现舞伴配对问题 (舞伴程序 c ).doc

上传人:yzhlya 2019/9/6 文件大小:63 KB

下载得到文件列表

数据结构--队列实现舞伴配对问题 (舞伴程序 c ).doc

文档介绍

文档介绍:数据结构--队列实现舞伴配对问题+(舞伴程序++c++)#include<iostream>#include<>constboolTURE=1;constboolFAULT=0;usingstd::cout;usingstd::cin;usingstd::endl;classNode{//链式堆栈的节点类public:Node();//构造函数重载1Node(int,int,int,Node*);//构造函数重载2voidconstget_data(int&,int&,int&);//取节点数据voidput_data(int,int,int);//置节点数据boolput_next(Node*);//置节点的前驱节点域boolput_prior(Node*);//置结点的后继结点域Node*constget_next()const;//取结点的前驱结点域Node*constget_prior()const;//取结点的后继结点域private:Node*next;Node*prior;intminute;intsecond;intnum;};Node::Node(){minute=NULL;second=NULL;num=0;next=NULL;prior=NULL;}Node::Node(intx,inty,intz,Node*p){minute=x;second=y;num=z;next=NULL;prior=p;}voidconstNode::get_data(int&x,int&y,int&z){x=minute;y=second;z=num;}voidNode::put_data(intx,inty,intz){minute=x;second=y;num=z;}boolNode::put_next(Node*n){next=n;returnTURE;}boolNode::put_prior(Node*p){prior=p;returnTURE;}Node*constNode::get_next()const{returnnext;}Node*constNode::get_prior()const{returnprior;}classQueue{public:Queue();//堆栈类的构造函数intget_length(void);//取堆栈的长度boolpush(int,int,int);//数据压栈boolpop(int&,int&,int&);//数据出栈voidprint(void);intconstseach(int);//搜索堆栈数据protected:Nodebase;//根节点Node*top;//顶节点intlength;};Queue::Queue():base()//构造函数,数据初始化{ length=0;top=&base;}intQueue::get_length(void)//取长度{ if(length<0)length=0; returnlength;}boolQueue::push(intminute,intsecond,intnum)//数据压栈{if(top!=NULL){ length++;Node*temp=newNode(minute,second,num,top);top->put_next(temp);top=temp;}else{returnFAULT;}returnTURE;}boolQueue::pop(int&minute,int&second,int&num){if(()!=NULL){ length--;Node*temp=();temp->get_data(minute,second,num);if(temp->get_next()!=NULL){ Node*temp1=temp->get_next(); temp1->put_prior(&base); (temp1);}else{ top=&base; (NULL);}deletetemp; }else{returnFAULT;}returnTURE;}intconstQueue::seach(intnum)//搜索堆栈数据{Node*temp;intx,y,z;temp=&base;while(temp!=NULL){temp->get_data(x,y,z);if(x==num)return1;temp=temp->get_next();}return0;}voidQueue::print()//打印堆栈{Node*temp;intx,y,z,n=1;temp=