1 / 9

The Stack

The Stack. What is it?.

efrat
Télécharger la présentation

The Stack

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. The Stack What is it?

  2. 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

  3. 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?

  4. 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)

  5. 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.

  6. 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.

  7. 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)

  8. 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

  9. Pointers Pointers reference the place in which the object is stored. It’s value is either an address or null.

More Related