Basically, it's to do with performance. A 'stack' is just an interface - it's a way of getting at the data for viewing and modification through some set of commands. However, this tells is nothing about how that data is stored in the structure - that's where stuff like ArrayStack
and LinkedStack
become important.
Essentially, each of these stacks is 'backed' by some more primitive structure - this is the bit behind the scenes that actually stores the data that we put in it. In the case of the ArrayStack
, this is an array - in the case of the LinkedStack
, this is a linked list.
So what's the difference? Well, consider the array. Arrays must use contiguous memory - namely, the whole array has to be given a block in memory which is one long uninterrupted chunk. On the other hand, a linked list consists of individual nodes linked by pointers - there is no requirement that it be contiguous at all. This makes resizing arrays problematic - essentially, we have to make a new array, and copy everything into it to resize it. This can be a problem with stacks, as we often have no idea precisely how large the stack will get. Linked lists don't have this problem - we just create a new node and link it to the list as it was before.
Thus, overall, the difference is memory use and performance - try implementing both and timing how they work with big data to see the difference.