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. Dear author
u missed check condition for 0(

View Tutorial          By: Maroof Ahmad at 2012-03-28 14:59:53

2. Very good tutorial, but I have a small question he
View Tutorial          By: Mohammad NABIL at 2010-07-20 05:58:19

3. How do i get tht GSM Connection .Can any one give
View Tutorial          By: srinivas raju at 2008-08-08 02:50:02

4. i am developing a video streaming pc server to j2m
View Tutorial          By: ziathegreat at 2009-05-19 13:19:15

5. A good short article on Struts. Require a step by
View Tutorial          By: Atul Saxena at 2012-01-09 19:56:59

6. Hello Sir,

Is there a way to use JS

View Tutorial          By: rohit at 2008-04-02 09:07:41

7. what is the use of int getch(void)
and unge

View Tutorial          By: sania at 2014-06-04 17:15:30

8. you have extended class Abc within class Abc

View Tutorial          By: SUNIL SHAH at 2012-05-25 06:17:23

9. good example tnq...........
View Tutorial          By: SaidiReddy at 2012-06-09 12:03:09

10. I have a problem with PortInUseException. I wrote
View Tutorial          By: robert at 2009-12-28 08:37:49