using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataStructures
{
    public class Stack<T>
    {
        public Stack(int length)
        {
            Nodes = new Node<T>[length];
        }

        public int Count { get; set; }

        public Node<T>[] Nodes { get; set; }

        public bool Push(params T[] newData)
        {
            if (newData.Length + Count > Nodes.Length)
                return false;

            for (int i = 0; i < newData.Length; i++)
            {
                Nodes[Count] = new Node<T>(Count, newData[i]);
                Count++;
            }

            return true;
        }

        public T Pop()
        {
            T returnData;

            if (Count == 0)
                return default(T);
            else
                returnData = Nodes[Count - 1].Data;

            Nodes[Count - 1] = null;
            Count--;

            return returnData;
        }

        public T Peek()
        {
            if (Count == 0)
                return default(T);
            else
                return Nodes[Count - 1].Data;
        }

        public override string ToString()
        {
            String outputStr = String.Empty;

            for (int i = 0; i < Count; i++)
                outputStr += Nodes[i].ToString();

            outputStr += String.Format("\n\n\tCapacity = {0}/{1}",
                Count, Nodes.Length);

            return outputStr;
        }
    }
}
