Store, check and delete information in a Stack object
The Stack class allows you to create a collection of data elements accessed on a last-in, first-out (LIFO) basis. It is part of the elsystem.collections namespace that also contains the Dictionary, GlobalDictionary, Vector, and Queue classes.
In other tutorials and programs I have tended to use Arrays, Dictionaries and Vectors because of their abilities to access data flexibly. For example, with a Vector it is possible to access date based on an index whereas with the Stack you can only:
- add an element at the ‘top’ of the stack (using the push method)
- delete an element at the ‘top’ of the stack (using the pop method)
- see what the element is at the ‘top’ of the stack (using the peek method)
It is also possible to clear and clone the stack. I demonstrate all these methods in a 9 minute video below.
The example program is available to Gold Pass members below so that they can experiment further with it.
Summary of tutorial 122
In this tutorial I demonstrate the stack class in the following steps:
- Add a data element
- Print the value of the element just added and a count of the stack
- Add a second data element
- Print the value of the element just added and a count of the stack
- Add a third data element
- Print the value of the element just added and a count of the stack
- Make a clone of the stack (with currently has 3 elements)
- Remove an element from the stack
- Print the element removed, the element at the top of the stack and the number of elements in the stack
- Remove all the elements from the stack
- Print the number of elements in the stack
- Print the contents of the clone of the stack (make in step 7)
- Demonstrate that an object can be added to a stack
Programming lessons
The tutorial demonstrates how to:
- Add and remove data from a stack
- Access the value of the data element at the top of the stack
- Clear all elements from the stack
- Clone a stack
- Add an object to a stack
and explains some differences between the stack and vector classes
The code is available free to Gold Pass members (see below).
Video explanation of tutorial 122
Gold Pass area
This content is for members only.THESE INDICATORS, SHOW ME STUDIES, STRATEGIES AND OTHER PROGRAMS HAVE BEEN INCLUDED SOLELY FOR EDUCATIONAL PURPOSES.
TO THE BEST OF MARKPLEX CORPORATION’S KNOWLEDGE, ALL OF THE INFORMATION ON THIS PAGE IS CORRECT, AND IT IS PROVIDED IN THE HOPE THAT IT WILL BE USEFUL. HOWEVER, MARKPLEX CORPORATION ASSUMES NO LIABILITY FOR ANY DAMAGES, DIRECT OR OTHERWISE, RESULTING FROM THE USE OF THIS INFORMATION AND/OR PROGRAM(S) DESCRIBED, AND NO WARRANTY IS MADE REGARDING ITS ACCURACY OR COMPLETENESS. USE OF THIS INFORMATION AND/OR PROGRAMS DESCRIBED IS AT YOUR OWN RISK.
ANY EASYLANGUAGE OR POWERLANGUAGE TRADING STRATEGIES, SIGNALS, STUDIES, INDICATORS, SHOWME STUDIES, PAINTBAR STUDIES, PROBABILITYMAP STUDIES, ACTIVITYBAR STUDIES, FUNCTIONS (AND PARTS THEREOF) AND ASSOCIATED TECHNIQUES REFERRED TO, INCLUDED IN OR ATTACHED TO THIS TUTORIAL OR PROGRAM DESCRIPTION ARE EXAMPLES ONLY, AND HAVE BEEN INCLUDED SOLELY FOR EDUCATIONAL PURPOSES. MARKPLEX CORPORATION. DOES NOT RECOMMEND THAT YOU USE ANY SUCH TRADING STRATEGIES, SIGNALS, STUDIES, INDICATORS, SHOWME STUDIES, PAINTBAR STUDIES, PROBABILITYMAP STUDIES, ACTIVITYBAR STUDIES, FUNCTIONS (OR ANY PARTS THEREOF) OR TECHNIQUES. THE USE OF ANY SUCH TRADING STRATEGIES, SIGNALS, STUDIES, INDICATORS, SHOWME STUDIES, PAINTBAR STUDIES, PROBABILITYMAP STUDIES, ACTIVITYBAR STUDIES, FUNCTIONS AND TECHNIQUES DOES NOT GUARANTEE THAT YOU WILL MAKE PROFITS, INCREASE PROFITS, OR MINIMIZE LOSSES.