题解 | #【模板】栈#
【模板】栈
https://www.nowcoder.com/practice/104ce248c2f04cfb986b92d0548cccbf
stack() //构造函数 { this->size = 3; space = new int[size]; Top = space; int n = 0; } //实现扩展内存的操作 bool expandmemory() { //申请一个更大的空间,比这个大2,然后讲新的地址赋给 int* tem = new int[size + 2]; size += 2; for (int i = 0; i < n; i++) { tem[i] = space[i]; } //内容复制完毕 Top = &tem[n + 1]; delete[]space; this->space = tem; return true; }