Stack data structure implemented by dynamic array
Stack (Stack) is a common data structure with last-in-first-out (LIFO) characteristics. In C++, we can use dynamic arrays to implement a stack data structure. Here is a detailed implementation example:
#include <iostream>
class Stack {
private:
int* array; // 动态数组
int top; // 栈顶索引
int capacity