Showing posts with label what is stack. Show all posts
Showing posts with label what is stack. Show all posts

Sunday, 16 December 2012

Stack implementation using Array in Java


import java.io.*;
class Aray
{
private int a[];
public int t=-1,i;
public Aray()
{
a=new int[5];
}
public void push(int val)
{
if(t<4)
{
t++;
a[t]=val;
}
else
System.out.println("Stack is full");
}
public int pop()
{
if(t==-1)
{
System.out.println("Stack is Empty");
return 0;
}
else
{
int temp = a[t];
t--;
return temp;
}
}
public void display()
{
if(t==-1)
{
System.out.println("Stack is Empty");
}
else
{
System.out.println("Elements from top to bottom");
for(i=t;i>-1;i--)
System.out.println(a[i]);
}
}

}

Best geography books for UPSC prelims, mains

This post is intended to clear the confusion that prevails among the aspirants over how to prepare for UPSC geography and the best books f...