Give the difference between Array and Stack?




What is the difference between An Array And Stack?

  • An array is the collection of ordered elements and Stack is also ordered collection of elements. 
  • An array is a static object while Stack is dynamic size object. 
  • Array contains the same data types while Stack may contain different data type. 
  • In array the elements are removed in any order while in case of Stack, It follows the LIFO i.e the last element added to the stack will be the first one to be removed.
  • Array stored in random order while Stack stored in LIFO order. 
  • Both are Linear data structures but the array may be multi-dimensional or one dimensional while the Stack is strictly one dimensional. 

No comments:

Post a Comment