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



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. Please tell me how to display the contents of stac
View Tutorial          By: Senthil at 2014-05-21 21:44:05

2. yes. Client needs to use printwriter, especially w
View Tutorial          By: Aksh at 2011-07-06 03:30:46

3. I am deveolper in envision .i am interested in scj
View Tutorial          By: shiva kumar at 2013-02-20 05:51:42

4. I have use the above code, Am getting the below er
View Tutorial          By: RameshKumar at 2011-07-25 05:02:12

5. You are using "this" to start to the thr
View Tutorial          By: sumit at 2014-10-30 08:14:55

6. @Zero Code

@
Catch ex As Ex

View Tutorial          By: Chitz at 2011-12-24 19:50:45

7. Great Job
View Tutorial          By: Niteen Dhule at 2015-02-09 06:37:03

8. Very good explanation . i understood easily
View Tutorial          By: whyte at 2014-03-25 10:12:00

9. Hi, Razvan

I change over to using y

View Tutorial          By: James at 2010-12-22 00:44:50

10. CTRL+C then CTRL+V :P
Complete Reference ;)

View Tutorial          By: Rahul A at 2012-03-21 14:12:56