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



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, Just what i was looking for.
View Tutorial          By: Baapu at 2009-10-21 15:21:43

2. we are java research students.
we are worki

View Tutorial          By: chetan at 2007-10-17 08:13:14

3. great.....
View Tutorial          By: rashid at 2009-12-07 03:22:46

4. dear sir ,
How can i create my smtp or host

View Tutorial          By: jignesh at 2011-03-14 01:42:11

5. Thanks for this great tutorial... was looking for
View Tutorial          By: Shashi at 2012-09-20 11:35:08

6. Thanks for the info
View Tutorial          By: info at 2010-01-31 12:17:58

7. Very Helpful.
View Tutorial          By: nfahem at 2012-05-09 10:50:29

8. very usefull article............ thanks to the aut
View Tutorial          By: runa at 2010-10-16 08:43:38

9. I want to know more about Java Garbage collection,
View Tutorial          By: Prosenjit Kundu at 2010-05-08 09:42:40

10. thanks or the infromation about switch statement
View Tutorial          By: mikko at 2008-09-01 23:48:44