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. When run this code then I am getting a blank page.
View Tutorial          By: Paritosh Chandra Dey at 2013-08-14 08:55:42

2. good one nice
View Tutorial          By: megha at 2011-07-16 15:54:29

3. Hii,,,i have a java server socket program and i wa
View Tutorial          By: prawinmasthan at 2012-01-13 08:38:35

4. Hi.. I tried it on blackberry... I have a problem
View Tutorial          By: jeremejazz at 2011-01-12 22:56:02

5. How make comunication between client and server, s
View Tutorial          By: alex at 2009-01-30 07:12:49

6. Superb article
View Tutorial          By: Raj at 2015-01-29 11:18:22

7. hello
plz tell me what can i do for sending

View Tutorial          By: mahipal at 2009-05-12 10:30:57

8. Does memmove care if the source is bytes and the d
View Tutorial          By: Paul at 2012-07-20 11:59:32

9. Cool! Downloading the whole file with the HttpCon
View Tutorial          By: Luddite at 2010-06-26 12:26:26

10. Hi Steven. It looks like your example program does
View Tutorial          By: Ben Hallinan at 2008-04-25 08:36:42