资源描述:
《数据结构__队列实现舞伴配对问题+(舞伴程序++c++)》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、.....#include#includeconstboolTURE=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(Nod
2、e*);//置节点的前驱节点域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
3、=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::g
4、et_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
5、;};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{ret
6、urnFAULT;}returnTURE;}boolQueue::pop(int&minute,int&second,int&num){if(base.get_next()!=NULL){length--;Node*temp=base.get_next();temp->get_data(minute,second,num);if(temp->get_next()!=NULL){Node*temp1=temp->get_next();temp1->put_prior(&base);base.put_next(temp1);}else{top=&base;base.p
7、ut_next(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=base.get_
8、next(