• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

arrays and stack

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
tell me the situation where stacks are better than arrays?
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 4
PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Amit Mmf Shrivastava wrote:He is right...


Jeanne is a "she".
 
Amit Mmf Shrivastava
Greenhorn
Posts: 4
PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne is a "she"



I am so Sorry for this...
Regards
Amit
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic