CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

SimpleStack

69 Views
Copy Code Show/Hide Line Numbers
   1:  public class SimpleStack<T>
   2:  {
   3:      private class Node<V>
   4:      {
   5:          public Node<V> Next;
   6:          public V Item;
   7:      }
   8:   
   9:      private Node<T> head;
  10:   
  11:      public SimpleStack()
  12:      {
  13:          head = new Node<T>();
  14:      }
  15:   
  16:      public void Push(T item)
  17:      {
  18:          Node<T> node = new Node<T>();
  19:          node.Item = item;
  20:          node.Next = head.Next;
  21:          head.Next = node;
  22:      }
  23:   
  24:      public T Pop()
  25:      {
  26:          Node<T> node = head.Next;
  27:          if (node == null)
  28:              return default(T);
  29:          head.Next = node.Next;
  30:          return node.Item;
  31:      }
  32:  }
by jaras
  March 09, 2010 @ 9:22am

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate