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. Very good. Keep it up.
View Tutorial          By: jk at 2009-05-23 11:00:29

2. example is ok, but plz increases the standard of e
View Tutorial          By: venky at 2009-05-19 01:29:04

3. yes simple good it wroking goog
View Tutorial          By: durga prasad pavirala at 2009-02-11 03:43:04

4. good but very simple program.........
View Tutorial          By: vipul at 2010-03-25 00:33:54

5. @mahesh yes you can use this to connect to any db
View Tutorial          By: Rita sen at 2012-01-05 05:18:13

6. Your answer was right on the money! After searchi
View Tutorial          By: ooh la la at 2013-07-19 20:33:41

7. very nice program but more info require
View Tutorial          By: pradeep at 2010-07-15 01:11:37

8. This tutorial is really Good and enhance my desire
View Tutorial          By: Yasin at 2011-07-09 10:04:57

9. simply nice.. Thank you.
View Tutorial          By: Anil at 2011-11-30 06:36:23

10. hi thanks for your tutorial, but I can`t run your
View Tutorial          By: yashar at 2015-05-29 18:57:30