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. Sir , I am doing BCA . I want to know more about j
View Tutorial          By: sandeep Namdev at 2008-09-16 05:47:22

2. I am getting the error below.

Tue J

View Tutorial          By: ganesh at 2008-07-01 05:35:31

3. Protip: you could add some inline assembly with th
View Tutorial          By: Robin Degen at 2011-08-16 23:47:04

4. Hello, I have executed the above code and it works
View Tutorial          By: Sana at 2010-02-01 03:50:18

5. tnx, nice code...
View Tutorial          By: Hansoc at 2009-08-18 00:17:58

6. its really helpfull to understand.
View Tutorial          By: rakhi at 2010-08-08 12:45:05

7. thanks or the infromation about switch statement
View Tutorial          By: mikko at 2008-09-01 23:48:44

8. very nice and i need the code for this.. can u sen
View Tutorial          By: bala at 2008-05-14 04:51:07

9. Thanks a lot!!!

Its very useful exp

View Tutorial          By: dipali at 2012-12-31 06:49:41

10. I am using my samsung s5233 via usb connection, ru
View Tutorial          By: Puneet at 2010-04-23 06:14:28