/* related posts with thumb nails */

Program to implement PUSH and POP operations on Stack using array method.:

class Stack

{

private static int MAX=10;

private int a[]=new int[MAX];

int top;

Stack()

{

top=0;

}

public void push(int v)

{

if(top

a[top++]=v;

else

System.out.println("Overflow");

}

public int pop()

{

if(top>0)

return a[--top];

else

{

System.out.println("Underflow");

return -1;

}

}

}

class StackArray

{

public static void main(String as[])

{

Stack s1=new Stack();

s1.push(30);

s1.push(40);

s1.push(50);

System.out.println(s1.pop());

System.out.println(s1.pop());

System.out.println(s1.pop());

}

}

/* Output */

50

40

30

Related Topics:

0 comments:

Post a Comment