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. crystal clear explanation
View Tutorial          By: digant at 2009-12-08 09:10:06

2. There is a major bug here. When i press backspace
View Tutorial          By: Rajasri at 2015-01-20 10:11:30

3. Java is very queit Langauge.
View Tutorial          By: Ashutosh Srivasatava at 2008-10-16 06:24:02

4. Thank you....
View Tutorial          By: Prakash at 2013-02-13 08:35:12

5. Hi Guys, thanks for sharing this... I have some mo
View Tutorial          By: Fins at 2011-12-14 04:40:09

6. Very nice.
Thanks

View Tutorial          By: Kaviya at 2015-02-23 13:48:15

7. Please let me know the SMSConnector number of any
View Tutorial          By: Chandra Shekhar at 2009-04-01 00:21:54

8. very nicely explained,
thank you

View Tutorial          By: Amin at 2010-04-14 09:40:30

9. Hello, I have been using a very similar code on de
View Tutorial          By: Rod at 2011-11-13 15:09:52

10. sir, could you please tell me about minimum and ma
View Tutorial          By: priya dwivedi at 2012-01-04 15:01:03