views:

81

answers:

4

what is the main feature of stack compare to arrays

+5  A: 

Stacks are LIFO and arrays have random access by index.

jball
A: 

A stack is dynamically sized and provides functionality for Last In, First Out retrieval of items.

An array is statically sized and does not provide any functionality (other than its indexer) for retrieving items in anything but random access.

Justin Niessner
A: 

Stacks are black boxes. You can just push a new item onto the top or pop the topmost item out (a third operation can be considered, which is peeking of the topmost element without removal). Stacks grow accordingly with elements that are added or removed.

Arrays instead are indexed structures that provide random access in constant time to its elements. They usually have a statically defined size (although it's possible to develop also dynamic arrays)

In anycase these two structures are quite orthogonal, a comparison between a linked list and a stack would be more senseful..

Jack
A: 
Jörg W Mittag