資源簡介
C++用棧來解決背包問題 經典數據結構問題 代碼精簡
代碼片段和文件信息
#include?“stack.h“
Stack::Stack(int?Size)
{
MaxSize=Size;
stack=new?int?[MaxSize];
if(stack==NULL)?return;
top=-1;
}
int?Stack::GetTop()?const
{
if(IsEmpty())??return-1;
else?return?stack[top];
}
bool?Stack::IsEmpty()?const
{
return?top==-1;
}
bool?Stack::IsFull()?const
{
return?top==(MaxSize-1);
}
bool?Stack::Push(cons
評論
共有 條評論