views:

42

answers:

3

What does a Push operation on a stack return?

A: 

That depends entirely on the stack implementation, I think. Some implementations might return nothing, others a boolean value, others still the stack object itself for chaining:

stack.push(element1).push(element2);
Tom Bartel
+1  A: 

This would depend on the implementation.

Push doesn't usually return anything as it adds an item you supply to the stack. The corresponding Pop operation would remove the item from the top of the stack and return it.

GraemeF
+1  A: 

It's not supposed to return anything. In .Net it's defined as a void function, for example.

Traveling Tech Guy
what does it returns in Java?
vaibhav
It returns the object you just pushed: http://java.sun.com/j2se/1.4.2/docs/api/java/util/Stack.html#push%28java.lang.Object%29
Traveling Tech Guy