What is the purpose of using a bag
object for the entries of an adjacency list in a graph? Why not use a data structure like a stack
or a queue
?
Asked
Active
Viewed 204 times
2

Paul Warnick
- 903
- 2
- 13
- 26
1 Answers
1
The most important part for adjacency list is that it is iterable. While stack or queue would certainly work, they aren't prefered data structures for iteration.
Another important property of bag is that it holds elements in order. It works as multiset in C++.

Neithrik
- 2,002
- 2
- 20
- 33