#include
#include
const bool TURE=1;
const bool FAULT=0;
using std::cout;
using std::cin;
using std::endl;
class Node{//链式堆栈的节点类
public:
Node();//构造函数重载1
Node(int , int , int ,Node *);//构造函数重载2
void const get_data(int &, int &,int &);//取节点数据
void put_data(int , int ,int );//置节点数据
bool put_next(Node *);//置节点的前驱节点域
bool put_prior(Node *);//置结点的后继结点域
Node* const get_next()const;//取结点的前驱结点域
Node* const get_prior()const;//取结点的后继结点域
private:
Node *next;
Node *prior;
int minute;
int second;
int num;
};
Node::Node()
{
minute=NULL;
second=NULL;
num=0;
next=NULL;
prior=NULL;
}
Node::Node(int x, int y, int z ,Node *p)
{
minute=x;
second=y;
num=z;
next=NULL;
prior=p;
}
void const Node::get_data(int &x, int &y, int &z)
{
x=minute;
y=second;
z=num;
}
void Node::put_data(int x, int y, int z)
{
minute=x;
second=y;
num=z;
}
bool Node::put_next(Node *n)
{
next=n;
return TURE;
}
bool Node::put_prior(Node *p)
{
prior=p;
return TURE;
}
Node* const Node::get_next() const
{
return next;
}
Node* const Node::get_prior() const
{
return prior;
}
class Queue{
public:
Queue();//堆栈类的构造函数
int get_length(void);//取堆栈的长度
bool push(int , int , int );//数据压栈
bool pop(int &, int & , int &);//数据出栈
void print(void);
int const seach(int );//搜索堆栈数据
protected:
Node base;//根节点
Node *top;//顶节点
int length;
};
Queue::Queue():base()//构造函数,数据初始化
{
length=0;
top=&base;
}
int Queue::get_length(void)//取长度
{
if(length<0) length=0;
return length;
}
bool Queue::push(int minute, int second, int num)//数据压栈
{
if(top!=NULL)
{
length++;
Node *temp=new Node(minute,second,num,top);
top->put_next(temp);
top=temp;
}
else
{
return FAULT;
}
return TURE;
}
bool Queue::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);
}