Comment on Tutorial - Stack example in Java - push(), pop(), empty(), search() By Henry



Comment Added by : srikanth

Comment Added at : 2014-05-30 06:44:58

Comment on Tutorial : Stack example in Java - push(), pop(), empty(), search() By Henry
import java.io.*;
import java.util.*;
class Stackdemo
{
public static void main(String []args)throws IOException
{
Stack<Integer> st=new Stack<>();
Buffer Reader br =new Buffer Reader(new InputStreamReader(System.in));
int element,pos,choice=0;
while(choice<4)
{
System.out.println("stack operation");
System.out.println("1 push element");
System.out.println("2 pop element");
System.out.println("3 search for element");
System.out.println("4 exit");
System.out.println("your choice");
choice=Integer.parseInt(br.readline());
switch(choice)
{
case1:
System.out.print("enter element:");
element =Integer.parseInt(br.readline());
st.push(element);
break;
case2:
Integer i=st.pop();
System.out.print("poped="+i);
break;
case3:
System.out.print("enter element");
element=Integer.parseInt(br.readline());
pos=st.search(element);
if(pos==-1)
System.out.println("element not found");
else
System.out.println("element found position:"+pos);
break;
default;
return;
}
System.out.println("Stack="+st);
}
}
}




}


View Tutorial



Subscribe to Tutorials

Related Tutorials

Program using concept of byte long short and int in java

Update contents of a file within a jar file

Tomcat and httpd configured in port 8080 and 80

Java File

Java String

Count number of vowels, consonants and digits in a String in Java

Reverse a number in Java

Student marks calculation program in Java

Handling Fractions in Java

Calculate gross salary in Java

Calculate average sale of the week in Java

Vector in Java - Sample Program

MultiLevel Inheritance sample in Java

Multiple Inheritance sample in Java

Java program using Method Overriding

Archived Comments

1. XML Parsing - Simplified.
Thanks.

View Tutorial          By: Piyush at 2011-05-19 22:56:23

2. Hi
I can able to execute the abov

View Tutorial          By: sruthy at 2010-07-23 03:29:39

3. Great guide. Missed the lecture, and this summed e
View Tutorial          By: Anonymous at 2008-12-21 19:36:19

4. can any body help me,i need to send a sms from sim
View Tutorial          By: vinayaka DJ at 2011-11-14 12:44:01

5. Very good example .!
Ty

View Tutorial          By: Mprogrammer at 2014-11-25 12:10:21

6. Hi,

I tried this script with noki

View Tutorial          By: sravan at 2009-07-11 11:17:45

7. Plz can u give me some more examples of recursion.
View Tutorial          By: Asadullah at 2010-01-23 06:38:58

8. good....
View Tutorial          By: Rini at 2013-01-08 10:44:54

9. What is the use of "SMSConnector" in thi
View Tutorial          By: Mudra at 2010-06-04 15:04:55

10. This should save some time

class pa

View Tutorial          By: vamsi gude at 2012-03-20 18:27:24