E N D
The Stack What is it?
Stack is a Simple DataStucture which allows Insert/Remove of Items at one end. It is basically called as LIFO (Last In First Out) data structure (i.e. the item which is added last is the first one to be removed) .NET has a built in class for Stack. It is found in the System.Collections namespace. Source: http://www.csharpfriends.com/Articles/getArticle.aspx?articleID=65 Data 4 Data 5 Data 3 Data 2 Data 1
Creating A Stack Stack MyStack = new Stack(10); Uses for a stack? In your C# games, this could be a high score list What other uses can you think of?
Adding To The Stack String MyWord = “Hello”; MyStack.Push(MyWord); This will ‘push’ the item into the stack, if the stack is full, it will (remember first in, last out)
Pop An Element Object MyOb = MyStack.pop().ToString(); This will ‘pop’, or return the last item of the stack, if the stack is empty, it will throw an exception.
Peek An Element Object MyOb = MyStack.peek().ToString(); This will allow you to view the item at the top of the stack without affecting it.
The Stack vs. The Heap The stack is the neat set of drawers where you can only access the top layer. The Heap is like the heap of clean laundry on our bed that we have not taken the time to put away yet - we can grab what we need quickly (that’s not an excuse)
The .Net Environment ... Is great because (finish the sentence in 10 words or less) “You don’t have to worry about memory management!” While .Net automates the process of memory management, it is still important to bear this in mind when designing code
Pointers Pointers reference the place in which the object is stored. It’s value is either an address or null.