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. hai,
i want to know how the connect

View Tutorial          By: V.Selvi at 2010-02-28 21:01:33

2. wow...great MAN
View Tutorial          By: Er Sounderarajan at 2013-03-13 07:29:58

3. I got some very useful information from this page
View Tutorial          By: King at 2008-01-08 20:26:21

4. nice info on struts and very good explanation
View Tutorial          By: bharadwaj kvnss at 2013-02-07 17:18:44

5. hi .the program does run thank you for that ,i nee
View Tutorial          By: mazen at 2008-09-09 04:55:16

6. Hello
I need some one send me runnable cod

View Tutorial          By: Ahmed Ghazey at 2010-08-09 01:55:48

7. It is very help full to me and very simple underst
View Tutorial          By: Reddymalla Babu Sircilla at 2013-02-22 08:28:22

8. hi! im new in j2me applications so i just cleaned
View Tutorial          By: resego at 2010-08-04 07:29:29

9. What a wonderful site for beginners? Now I can pra
View Tutorial          By: Kafedha Rwezaula at 2010-06-03 04:39:59

10. Would u please provide me with a solution about ho
View Tutorial          By: milan at 2011-02-17 05:39:38