Initializing stacks
Each language provides varying levels of support for the stack data structure. The following are some examples of initializing the collection, adding an object to the collection, and then removing the top object from the collection.
C#
C# provides a concrete implementation of the stack data structure through the Stack<T>
generic class.
Stack<MyObject> aStack = new Stack<MyObject>(); aStack.Push(anObject); aStack.Pop();
Java
Java provides a concrete implementation of the stack data structure through the Stack<T>
generic class.
Stack<MyObject> aStack = new Stack<MyObject>(); aStack.push(anObject); aStack.pop();
Objective-C
Objective-C does not provide a concrete implementation of the stack data structure, but one can be easily creating using the class cluster NSMutableArray
. Be aware that this will create an array-based implementation of the stack, which is generally less efficient...