// Quiz 8 solution
/////////////////////////////////////////////////////////////////////
class myListStack
   {       	
   private LinkList stackArray;

   // variable to track size of stack; ideally this would just happen in the
   // LinkList class, but that is currently missing a method that returns
   // the size and so we have to do this explicitly in this class
   private int size;            	   	
//------------------------------------------------------------------

   public myListStack()                		// constructor takes 0 arguments
      {                   
      stackArray = new LinkList(); 		// creates new empty linked list
      size = 0;                    		// initialize size to 0
      }
//------------------------------------------------------------------
   public void push(int j)  			// push a value on the stop of the stack
      {
	   stackArray.insertFirst(j);           // put j on top of stack
	   size++;  				// increment size
      }
//------------------------------------------------------------------
   public int pop()                		// pop the top item off the stack
      {
	   size--;		   		// decrement size
      	   return stackArray.removeFirst();     // return item
      }
//------------------------------------------------------------------
   public int peek()          	             	// peek at top of stack
      {
      return stackArray.element();		// return the value
      }
//------------------------------------------------------------------
   public boolean isEmpty()   	               	// is stack empty?
      {
      return (size == 0);    			// this will return TRUE if it is empty
      			                        // otherwise FALSE
      }
//------------------------------------------------------------------
   }  // end class myListStack
////////////////////////////////////////////////////////////////////

