Back to notes -- Keyboard shortcut: 'u'        next -- Keyboard shortcut: 'n'  Slide program -- Keyboard shortcut: 't'    A solution to the exercise.Lecture 0 - slide 19 : 25
Program 1
using System;

public class StackWithArray: Stack{ 

  private Object[] elements;
  private int nextPush;
  private int MaxSize; 

  public StackWithArray(int MaxSize){
    elements = new Object[MaxSize];
    nextPush = 0;
    this.MaxSize = MaxSize;
  }
  
   public override void Push(Object el){
     if (!Full){
       elements[nextPush] = el;
       nextPush++;
    }
  }

   public override void Pop(){
   if (!Empty)
     nextPush--;
   }

   public override Object Top{
    get{
      if (!Empty)
         return elements[nextPush-1];
      else return "not possible";}
   }

   public override bool Full{
    get{return nextPush >= MaxSize;}
   }

   public override bool Empty{
    get{return nextPush == 0;}
   }

   public override int Size{
    get{return nextPush;}
   }   

  public override String ToString(){
    string res = "Stack: ";
    for(int i = 0; i < nextPush; i++){
      res += elements[i] + " ";}
    return res;
  }

}