mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-06 14:27:26 +08:00
Format C++ codes in Clang-Format Style: Microsoft
This commit is contained in:
@ -8,10 +8,10 @@
|
||||
|
||||
/* 基于数组实现的栈 */
|
||||
class ArrayStack {
|
||||
private:
|
||||
private:
|
||||
vector<int> stack;
|
||||
|
||||
public:
|
||||
|
||||
public:
|
||||
/* 获取栈的长度 */
|
||||
int size() {
|
||||
return stack.size();
|
||||
@ -35,7 +35,7 @@ public:
|
||||
|
||||
/* 访问栈顶元素 */
|
||||
int top() {
|
||||
if(empty())
|
||||
if (empty())
|
||||
throw out_of_range("栈为空");
|
||||
return stack.back();
|
||||
}
|
||||
@ -46,11 +46,10 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/* Driver Code */
|
||||
int main() {
|
||||
/* 初始化栈 */
|
||||
ArrayStack* stack = new ArrayStack();
|
||||
ArrayStack *stack = new ArrayStack();
|
||||
|
||||
/* 元素入栈 */
|
||||
stack->push(1);
|
||||
@ -59,7 +58,7 @@ int main() {
|
||||
stack->push(5);
|
||||
stack->push(4);
|
||||
cout << "栈 stack = ";
|
||||
PrintUtil::printVector(stack->toVector());
|
||||
printVector(stack->toVector());
|
||||
|
||||
/* 访问栈顶元素 */
|
||||
int top = stack->top();
|
||||
@ -68,7 +67,7 @@ int main() {
|
||||
/* 元素出栈 */
|
||||
stack->pop();
|
||||
cout << "出栈元素 pop = " << top << ",出栈后 stack = ";
|
||||
PrintUtil::printVector(stack->toVector());
|
||||
printVector(stack->toVector());
|
||||
|
||||
/* 获取栈的长度 */
|
||||
int size = stack->size();
|
||||
|
Reference in New Issue
Block a user