cheku.cpp
来自「数据结构 停车场管理 栈和队列的应用 双栈 停车场 便道问题」· C++ 代码 · 共 50 行
CPP
50 行
// cheku.cpp: implementation of the cheku class.
//
//////////////////////////////////////////////////////////////////////
#include "cheku.h"
#include <iostream.h>
#include <stdlib.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
cheku::cheku(int size):top(-1),MaxSize(size)
{
S=new int[MaxSize]; //创建存储栈的数组
}
void cheku::ruku(int x)
{
if (top==MaxSize-1) throw "车库满!";
top++; //车库未满,则入库
S[top]=x;
}
int cheku::chuku()
{
int item;
if (top==-1) throw "车库空";
item=S[top--];//等价于item=S[top];top--;
return item;
}
int cheku::Find(int a)
{
for(int i=top;i>=0;i--)
{
if(a==S[i])
return i;
}
return 0;
}
bool cheku::Full()
{
if(top==MaxSize-1)
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?