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



Ask a Question

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. Thank you so much
View Tutorial          By: Daniel at 2011-02-14 22:47:05

2. dear sir/madam
I am using netbeans IDE 7.0

View Tutorial          By: bangaram at 2011-07-19 12:03:04

3. thanks..very nice and easy to understand for new j
View Tutorial          By: Ranjan at 2011-07-22 08:34:50

4. super j2me introduction
View Tutorial          By: govinth at 2012-02-05 09:33:18

5. Your post helped me to resolve the SSH exception..
View Tutorial          By: Ashwini at 2008-07-14 12:47:32

6. superb superb maza aggaya maza aggaya
View Tutorial          By: pramodh at 2012-04-16 05:21:54

7. Can anybody explain me what are the minimum settin
View Tutorial          By: Ramesh at 2010-02-25 10:28:42

8. My code runs smoothly. I have taken some steps for
View Tutorial          By: Amit Shrivastava at 2015-01-25 13:48:46

9. I get this error:
Can someone please help m

View Tutorial          By: Carlos at 2010-06-14 02:42:53

10. Thanks this article helped (just needed to know wh
View Tutorial          By: sushi at 2008-12-17 08:09:51