| Author |
arrays and stack
|
jai ahuja
Greenhorn
Joined: May 17, 2012
Posts: 4
|
|
|
tell me the situation where stacks are better than arrays?
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26173
|
|
|
They are different data structures. A stack is good for when you want to retrieve the last element added. An array is when you want to access any element at any time.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
Amit Mmf Shrivastava
Greenhorn
Joined: Oct 30, 2012
Posts: 4
|
|
Hello Jai,
I understand your question, that you want to know where Stacks is better than Arrays, as well as I read the comment of Jeanne as:
Jeanne Boyarsky wrote:They are different data structures. A stack is good for when you want to retrieve the last element added. An array is when you want to access any element at any time.
He is right, also I want to add some thing in his statement that size of stack is not limited while in array it is limited. And implementing a stack as an array is a bit more straightforward since we only need to keep track of the last element. We don't need to consider shunting items towards the head anymore, but we must still accommodate for new items which means we still waste memory allocating unused elements.
Regards
Amit
|
PHP Training Indore | Java Training Indore | .Net Training Indore
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9944
|
|
Amit Mmf Shrivastava wrote:He is right...
Jeanne is a "she".
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
Amit Mmf Shrivastava
Greenhorn
Joined: Oct 30, 2012
Posts: 4
|
|
Jeanne is a "she"
I am so Sorry for this...
Regards
Amit
|
 |
 |
|
|
subject: arrays and stack
|
|
|