C
C
cybernoob2018-03-13 15:14:04
Data Structures
cybernoob, 2018-03-13 15:14:04

How to understand the stack if I don't know C?

I know everything about the stack: what data can be put into it, who we put the last one - we take the first one, that only three operations are supported: Push, Pop and Top.
The question is especially relevant due to the fact that in some sources they write "inside the stack is implemented as a dynamic array."
Question: so why can't you take and refer to the very first - the bottom element, either by index if it is an array, or by a banal enumeration as in a linked list? It is clear that this will take longer, inefficient, but what was the separate data structure for? That's what they would call: an array in which operations are carried out only with the last element.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SagePtr, 2018-03-13
@SagePtr

And who told you that the stack will necessarily be implemented as an array? Suddenly there will be a list, each element of which refers to the previous one, and you only have a pointer to the last element? How then can you refer to the first one without iterating through all the elements? That's the same.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question