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. Thanks sir i am understand to jdbc but who will ru
View Tutorial          By: Ranjeet singh at 2012-05-04 07:40:29

2. DO NOT USE QSORT IN A C++ CODE.

If

View Tutorial          By: paercebal at 2008-08-13 05:06:45

3. Thanks to OP and Zarno for finishing off this code
View Tutorial          By: Soapy Balls at 2011-05-27 05:26:13

4. nativeFinalize: Error closing Handle 6
and

View Tutorial          By: yash at 2008-05-16 17:43:42

5. The program will work only need to change

View Tutorial          By: LEENA NARULA at 2012-06-15 06:45:06

6. Hallo.

And if the certificate is se

View Tutorial          By: Mario at 2009-11-11 08:42:46

7. nested for loop
View Tutorial          By: SAJAN at 2011-03-15 12:42:36

8. This was very helpful! Thanks!!!
View Tutorial          By: Andreas Clausen at 2009-09-03 15:07:14

9. this tutorial example of inheritence is taken from
View Tutorial          By: vinod kumar gaur at 2011-07-17 23:18:00

10. that's what I've been looking for!!!!!!!!!!!!!!!!!
View Tutorial          By: bibi at 2014-12-28 20:43:56