SHARE
TWEET

Moshe Binieli - TDD

a guest Nov 14th, 2018 370 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. namespace Stack
  2. {
  3.     public class Stack<T>
  4.     {
  5.         #region Members
  6.         private T[] stackArray;
  7.         private int maximumLength;
  8.         #endregion
  9.  
  10.         #region Properties
  11.         public int Size { get; private set; }
  12.         #endregion
  13.  
  14.         #region Constructor
  15.         public Stack(int length)
  16.         {
  17.             maximumLength = length;
  18.             stackArray = new T[length];
  19.         }
  20.         #endregion
  21.  
  22.         #region Public Methods
  23.         public void Push(T value)
  24.         {
  25.             if (Size == maximumLength)
  26.                 throw new ExceededSizeException();
  27.  
  28.             stackArray[Size++] = value;
  29.         }
  30.  
  31.         public T Pop()
  32.         {
  33.             if (Size == 0)
  34.                 throw new ExpenditureProhibitedException();
  35.  
  36.             return stackArray[--Size];
  37.         }
  38.  
  39.         public T Peek()
  40.         {
  41.             if (Size == 0)
  42.                 throw new ExpenditureProhibitedException();
  43.  
  44.             return stackArray[Size - 1];
  45.         }
  46.         #endregion
  47.     }
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top