You are on page 1of 2

/*

* To change this license header, choose License Headers in Project Properties.


* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package stackapp;
/**
*
* @author hnd
*/
class Stack
{
int nelements;
int top;
String StudentNo[];
public Stack(int max)
{
nelements=0;
top=-1;
StudentNo=new String[max];
}
public void push(String number)
{
StudentNo[++top]=number;
nelements++;
}
public boolean isEmpty()
{
return (nelements==0);
}
public boolean isfull()
{
return (nelements==StudentNo.length);
}
public String POP()
{
nelements--;
return StudentNo[top--];
}
public String peek()
{
return StudentNo[top];
}
}
public class StackApp {
public static void main(String[] args)
{
Stack myobj=new Stack(5);
myobj.push("AA ");
myobj.push("BB ");
myobj.push("CC ");
myobj.push("DD ");

System.out.println("Peek "+myobj.peek());
System.out.println("POP "+myobj.POP());
System.out.println("Peek "+myobj.peek());
}
}

You might also like