Basic Stack Implementation in Java

import java.util.*;

/**
*Program to test Sample stack implementation.
* @author asharda
*
*/
public class stack_1 {

static Stack<Integer> s =new Stack <Integer>();
public static void main(String[] args) {

push();
pop();
display();
}

public static void push()
{

s.push(10);
s.push(20);
s.push(30);
System.out.println(“Firest element of stack is “+s.peek());
}

public static void pop()
{
s.pop();
System.out.println(“Firest element of stack is “+s.peek());
}

public static void display()
{
System.out.println(“Content of stack now is “);
for(int i=s.size()-1;i>=0;i–)
{
System.out.println(s.elementAt(i));
}

}
}

Advertisements

About qainterviews

Software Geek,QA Expert,Blogger
This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s