Cleopatra
Cleopatra

Reputation: 55

Which type of data structure is a stack?

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?

Upvotes: 2

Views: 4068

Answers (2)

Ibukun Muyide
Ibukun Muyide

Reputation: 1298

Well, first of all, Stack is a data structure on its own. Stack are to be expandable which ever implementation used. Although stack can be fixed in size, maximum number of element it can contain. but often you will like to consider it as a dynamic structure that expands as the number of elements increase. Often it comes as ADT(Abstract data type) so that which ever structure(LinkedList, Array, ArrayList etc) is used to implement it, its functions and attributes are always the same

Upvotes: 0

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 726779

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.

Upvotes: 5

Related Questions