stack.cpp
来自「hello everybody. good lucky to you」· C++ 代码 · 共 41 行
CPP
41 行
// Borland C++ - (C) Copyright 1991 by Borland International
// stack.cpp: Implementation of the Stack class
// from Hands-on C++
#include <iostream.h>
#include "stack.h"
int Stack::push(int elem)
{
int m = getmax();
if (top < m)
{
put_elem(elem,top++);
return 0;
}
else
return -1;
}
int Stack::pop(int& elem)
{
if (top > 0)
{
get_elem(elem,--top);
return 0;
}
else
return -1;
}
void Stack::print()
{
int elem;
for (int i = top-1; i >= 0; --i)
{ // Print in LIFO order
get_elem(elem,i);
cout << elem << "\n";
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?