class StackFixedTop
{   int a[];
    int elements;
    StackFixedTop(int size)
    {   a=new int[size];
        elements=0;
    }
    public void push(int value)
    {   if(elements==a.length)
        {   System.out.println("Overflow");
        }
        else
        {   elements++;
            for(int i=elements-1; i>0; i--)
            {   a[i]=a[i-1];
            }
            a[0]=value;
        }
    }//push
    public int pop()
    {   if(elements==0)
        {   System.out.println("Underflow");
            return 0;
        }//if
        else
        {   elements--;
            int temp=a[0];
            for(int i=0; i<elements; i++)
            {   a[i]=a[i+1];
            }//for
            return temp;
        }//else
    }//pop
    public void lifo() //for traversal
    {   for(int i=0; i<elements; i++)
        {   System.out.print(a[i]+" ");
        }
        System.out.println();
    }
    public int peek()
    {   return a[0];
    }
    public static void main(String args[])
    {   StackFixedTop stack=new StackFixedTop(5);
        stack.push(1);
        stack.push(2);
        stack.push(3);
        stack.push(4);
        stack.push(5);
        stack.push(6);
        stack.lifo();
        stack.pop();
        stack.pop();
        stack.push(7);
        stack.lifo();
    }//main
}//class
/*Output
Overflow
5 4 3 2 1
7 3 2 1
*/

/*
Note:- Not that I recommend this program 
but some children argue for this till they 
have not understood computational complexity.
*/




