简体   繁体   English

是否可以将堆栈视为具有成员函数的数组?

[英]Can a stack just be thought of as an array with member functions?

假设我们使用的是堆栈的数组实现,而不是链表实现。

Not exactly. 不完全是。 You can rather see a stack colletion as a wrapper around an array. 您宁可将堆栈集合视为数组的包装器。

An array is allocated with a fixed size, while a stack grows with the data that is added to it. 数组分配的大小固定,而堆栈随着添加的数据增长。 Generally this is done by allocating a small array initially, and allocate a larger array when the data outgrows the current array. 通常,这是通过首先分配一个小的数组来完成的,并在数据超出当前数组的数量时分配一个更大的数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM