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. i want to study c-programming language
View Tutorial          By: rajesh at 2008-07-27 07:43:09

2. That's a very nice and simple article,
Tha

View Tutorial          By: Mohsen at 2009-10-11 03:07:18

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

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

If

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

5. its great!!!!
View Tutorial          By: safrgdg at 2015-02-12 10:10:07

6. very nice i now understand what the allocated part
View Tutorial          By: Digistr - digistrscape (youtube.com/digistrscape) at 2010-01-30 01:17:19

7. how to code for images hitting in jsp like googl
View Tutorial          By: Kumaravel at 2014-08-06 11:23:08

8. why 27's example is prone to a deadlock ? when pro
View Tutorial          By: kaka at 2011-08-14 00:59:41

9. It worked for me. Thanks a lot. Hi Sasikumar, I th
View Tutorial          By: Ramlak at 2007-03-05 01:53:14

10. hi, ashray p shetty
can you please tell me

View Tutorial          By: amrish at 2010-12-12 07:30:49