Stack as an array Data Structure
Stack contains an ordered collection of elements. An array is used to store ordered list of elements. Hence, it would be very easy to manage a stack if we represent it using an array. However, the problem with an array is that we are required to declare the size of the array before using it in a program. This means the size of an array should be fixed. Stack on the other hand does not have any fixed size. It keeps on changing, as the elements in stack are popped or pushed.
Though an array and a stack are totally different data structures, an array can be used to store the elements of a stack. We can declare the array with a maximum size large enough to manage a stack. As a result, the stack can grow or shrink within the space reserved for it.
No comments:
Post a Comment