📄 stack.cpp
字号:
/*
* 学 号:B05031126
*
* 作 者:南京邮电大学计算机学院 吴登荣
*
* 摘 要:本程序是一个完整的后缀表达式计算,主要用栈的操作实现,本程序封装了CStack类实现
* 栈的操作,本程序最大的特色在乎运用实时监控的算法对表达式进行数据校验,对一切合
* 法的表达式进行计算,检验出所有任何非法表达式并提示。
*
* 完成日期:2006年9月25日
*
* E - mail:Jeffrey.nupt@gmail.com
*/
// Stack.cpp: implementation of the CStack class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "B05031126.h"
#include "Stack.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CStack::CStack()
{
for(int i=0;i<=50;i++)
num[i]=0;
sum=0;
flag=1;//假设所有操作均合法
popcount=0;
pushcount=0;
}
int CStack::getflag()
{
return flag;
}
int CStack::getsum()
{
return sum;
}
void CStack::setflag(int tempflag)
{
flag=tempflag;
}
int CStack::getcount()
{
return (pushcount*2-popcount)/2;
}
void CStack::Pop()
{
if(sum>=1)//判断是否非法操作
{
num[sum]=0;
sum--;
popcount++;
}
else
{
flag=0;
}
}
void CStack::Push(int temp)
{
sum++;
num[sum]=temp;
pushcount++;
}
int CStack::Top()
{
if(sum>=1)//判断是否非法操作
{
return num[sum];
}
else
{
flag=0;
}
}
CStack::~CStack()
{
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -