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. good explanation.
View Tutorial          By: praneeth at 2011-06-20 23:28:00

2. Hi santhosh,
Try it ou

View Tutorial          By: Kiran at 2011-12-14 04:31:29

3. How to do the following
Create a class With

View Tutorial          By: Anurag at 2014-01-03 10:14:45

4. nice article... got th topic clearly
View Tutorial          By: praba at 2011-05-09 23:29:26

5. please let me know the complete refernce with samp
View Tutorial          By: NARI at 2009-04-11 23:50:03

6. writa a java program to add two one-dimensional ar
View Tutorial          By: nibedita swain at 2011-08-22 15:23:37

7. i am new to java, please send simple programs, and
View Tutorial          By: jegan at 2011-07-11 02:22:37

8. Hi,
I have loaded all 5 java classes and i

View Tutorial          By: DurgaPrasad at 2011-11-24 06:02:19

9. Thanks
View Tutorial          By: Akhilesh at 2010-04-05 11:31:17

10. pls give us aprogram of postfix and infix using st
View Tutorial          By: lost_hope1111 at 2009-02-13 01:48:37