Several enhancements and fixes

This commit is contained in:
krahets
2023-09-14 03:36:31 +08:00
parent a9d70e9e4b
commit d190dbf3c1
18 changed files with 84 additions and 70 deletions

View File

@ -18,8 +18,8 @@ class ArrayStack {
}
/* 判断栈是否为空 */
bool empty() {
return stack.empty();
bool isEmpty() {
return stack.size() == 0;
}
/* 入栈 */
@ -35,7 +35,7 @@ class ArrayStack {
/* 访问栈顶元素 */
int top() {
if (empty())
if (isEmpty())
throw out_of_range("栈为空");
return stack.back();
}
@ -74,7 +74,7 @@ int main() {
cout << "栈的长度 size = " << size << endl;
/* 判断是否为空 */
bool empty = stack->empty();
bool empty = stack->isEmpty();
cout << "栈是否为空 = " << empty << endl;
// 释放内存