In general, Bag doesn't implies a sequenced structure (of course you can use a list to implement the internal structure, but not all the Bag does). Hence, it is possible that after we put a series of objects to the Bag, we cannot get them back in the sequence we expected, in fact, we lost the sequence. Therefore, a Bag may not necessary able to perform all the tasks done by a Stack.
But it's true that many programmers in the market work around with their data structure as you did. They use a list to store objects and implement bag alike methods, with put() where they can specify the exact location to store the object, but this is not simply a Bag anymore.
No comments:
Post a Comment