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. can u please explain java scripts for menus.
View Tutorial          By: web designers in kerala at 2011-04-16 02:08:22

2. Hi, i am new java, and i want to become gud develo
View Tutorial          By: amit at 2012-02-16 12:21:25

3. Any Solution for below Error,

*** t

View Tutorial          By: Mazher at 2009-08-02 02:08:52

4. The tutorial is simple and clear.
@Gnani, i

View Tutorial          By: Tayo at 2010-01-03 13:10:24

5. Unable to connect with https:\\localhost:8443 but
View Tutorial          By: gopala krishna at 2012-04-02 07:17:09

6. it is really BEST answer of my question.
MR

View Tutorial          By: Ramesh genwa at 2010-09-09 07:15:37

7. can for statement be used in a switch statement fo
View Tutorial          By: Osei Quadwo at 2014-10-08 20:12:17

8. I am trying to execute the same code but still una
View Tutorial          By: Sona at 2015-06-11 18:35:13

9. Good morning!
I need help about how to conf

View Tutorial          By: alpha at 2009-06-14 03:20:41

10. Cool it help me a lot
View Tutorial          By: urdu sms at 2009-10-06 12:16:20