biandao.cpp
来自「数据结构 停车场管理 栈和队列的应用 双栈 停车场 便道问题」· C++ 代码 · 共 53 行
CPP
53 行
// biandao.cpp: implementation of the biandao class.
//
//////////////////////////////////////////////////////////////////////
#include "biandao.h"
#include <stdlib.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
biandao::biandao( )
{
front=rear=NULL;
}
void biandao::Enbiandao(int x)
{
Node *s;
s=new Node;
s->data=x; //申请一个数据域为x的结点s
s->next=NULL;
if(front==NULL)//空队列,新结点既是队头,又是队尾
{
front=rear=s;
}
else
{ rear->next=s; //将结点s插入到队尾
rear=s;
}
}
int biandao::Debiandao()
{
Node *p;
int x;
if (front==NULL) throw "便道空";
p=front;
x=p->data; //暂存队头元素
front=front->next; //将队头元素所在结点摘链
if (front==NULL)
rear=front; //判断出队前队列长度是否为1
delete p;
return x;
}
bool biandao::Empty()
{
if (front==NULL)
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?