哪种数据结构是栈?数据结构、哪种

2023-09-07 03:21:13 作者:余生伴你流浪

我有一个简单的问题:堆栈是哪种数据结构?它是静态数据结构还是动态数据结构?我一直在寻找答案但找不到它,因此我得到了自己的解释"——我想,当你可以通过使用数组或链表来实现它时,它可以是......两者?,取决于在执行?我的推理有意义吗?

I got one simple question: which kind of data structure is a stack? Is it a static or dynamic data structure? I was looking for the answer and couldn't find it, therefore I got my own "explanation" - I guess, when you can implement it either by using an array or a linked list, it can be... both?, depending on implementation? Does my reasoning make any sense?

推荐答案

根据定义,静态数据结构具有固定大小.如果您可以将堆栈的大小限制为某个预先确定的数字,那么您的堆栈将成为静态数据结构.它的大小是它的存储大小,加上堆栈指针或指示当前位置的堆栈索引的大小.

By definition, a static data structure has fixed size. If you can limit the size of your stack to some pre-determined number, your stack becomes a static data structure. Its size is the size of its storage, plus the size of the stack pointer or stack index indicating the current location.

无限容量的堆栈是一种动态数据结构,无论其实现如何.它可以使用链表或数组来实现,您在达到其容量时重新分配,但是当您添加或删除数据时,此类堆栈的大小会发生变化.

A stack of an unlimited capacity is a dynamic data structure, regardless of its implementation. It could be implemented with a linked list or an array that you re-allocate upon reaching its capacity, but the size of such stack changes as you add or remove data.