Stack using Linked List in Java

import java.util.LinkedList;
import java.util.Scanner;

/**
*
*/

/**
* @author ashish
*
*/
public class stack {

static LinkedList<Integer>list=new LinkedList<Integer>();
static Scanner in =new Scanner(System.in);
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int choice;
do
{
System.out.println(“Enter your choice”);
System.out.println(“1:Push”);
System.out.println(“2:Pop”);
System.out.println(“3:Display”);
System.out.println(“4:Exit”);

choice=in.nextInt();
switch(choice)
{

case 1:
push();
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
System.out.println(“Exiting”);
System.exit(0);
}

}while(choice !=4);

}

public static void push()
{
System.out.println(“Enter the numbers you want to enter”);
System.out.println(“Now enter the elements”);
int temp=in.nextInt();
list.push(temp);
}

public static void pop()
{
System.out.println(“Now Popping”);
list.pop();

}

public static void display()
{
System.out.println(“Displaying Stack”);
for(int i:list)
System.out.println(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