Normally the data containers do not save the raw data but a structure that wraps the data and describes the way in which one data is related to the next; this structure is usually called Node in many implementations.
For example, if you have Nodes that are related only to the next Node it would result in a list just linked , if instead it were linked to the next and previous node, it would be a list doubly linked , if you have a relationship higher-lower you could have a Node of binary tree or if the Node can contain multiple children it may be a < a href="https://en.wikipedia.org/wiki/%C3%81rbol_de_Merkle"> hash tree .
Stacks " stacked " data one on another and all operations are performed on the upper element; that type of behavior is easy to implement with a list simply linked, since you can point to the upper node and you will have data while the nodes have other nodes " below ".
Pila has no nodes, so you have no way of describing how one data relates to the next, and therefore (as you have already observed) there is no way to easily manage the stack. But that does not mean it's impossible ...
Formations 1 .
Why does it really define the vector as a simple pointer within the class?
C ++ formations are a contiguous space in memory that store a type of data, the way to access them is through arithmetic of pointers . This is that by having a pointer to an element, you can add a value N to this pointer to access the Nth element from that pointer (or subtract N to access the Nth previous element); for this reason you can express a formation of arbitrary size with a simple pointer.
Your class stack.
We see that it has three members:
tElemento *elementos; //Vector de elementos
int Lmax; //Tamaño del vector
int tope_; //Posicion del tope
Surely you expect to implement the stack by using a fixed-size array (stored in
Also known as arrays or English arrays.
Lmax ) and remembering to which position elements are stored using the variable
tope_ ; it is a type of implementation that can be more efficient than the implementation using Nodes as long as you have an initial training (vector elements) sufficiently large ... but if you exceed this initial capacity you should ask for memory again and re-host the above elements, which is usually very expensive.