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



Comment Added by : eissen

Comment Added at : 2014-09-22 13:32:20

Comment on Tutorial : Stack example in Java - push(), pop(), empty(), search() By Henry
public class zcxzcStack
{
//push function/method
// please change the code thank you
static int[] push(int [] stack, int element, int top )
{
stack[++top] = element;
return stack;
}
// please change the code thank you
//pop function/method
static int[] pop(int [] stack, int top)
{
int pop = 0;
stack[top--] = pop;
return stack;
}
// please change the code thank you
//display
public static void main (String[]args)
{
int stack[] = new int[10];
int top = -1;

//push
stack = push(stack,12,top++);
stack = push(stack,13,top++);
stack = push(stack,14,top++);

/*//Pop
stack = pop(stack,top--);

*/
//set elements to -1;
// please change the code thank you
for ( int i = 0; i < stack.length; i++ )
if (stack[i] !=0 )
System.out.print(stack[i] + " ");
System.out.println();
// please change the code thank you
}
}


View Tutorial



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. it's very usefull to the users who were in startin
View Tutorial          By: Harichandana at 2013-02-28 04:37:17

2. good
View Tutorial          By: epuri at 2008-09-09 01:05:56

3. Hi i am sanjay ,
I got the exact difference

View Tutorial          By: Sanjay Patel at 2012-05-06 11:36:00

4. I need full code for how to connnect pc to mobile
View Tutorial          By: Vijay at 2009-08-23 23:38:05

5. can for statement be used in a switch statement fo
View Tutorial          By: Osei Quadwo at 2014-10-08 20:12:17

6. Dear !

Thanks for the article. Now

View Tutorial          By: Mubasher at 2013-05-04 11:37:52

7. why push is error in st.push(new Integer(a)); ? an
View Tutorial          By: ann at 2015-02-02 09:23:41

8. ahmm I guess This is a VB6 program? or how can I g
View Tutorial          By: kelvin at 2011-02-27 14:07:44

9. good work.
if there is a ValidatorForm the

View Tutorial          By: floriano at 2008-10-09 07:23:16

10. Awesome script. works like a charm.


View Tutorial          By: blestab at 2011-03-02 04:32:35