Advertisement
Guest User

Moshe Binieli - TDD

a guest
Nov 14th, 2018
1,503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement