Why there is no Tree data structure in STL?
Is it not needed so much? Or can it be done easily with other Data Structures?
Why there is no Tree data structure in STL?
Is it not needed so much? Or can it be done easily with other Data Structures?
My guess is that trees were not included since they (as in balanced binary trees) are typically used to implement sets and maps, and these are already included.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
STL provides containers, not data structures. The std::map container is, most likely, implemented as a binary tree. It must be so, in order to guarantee the time complexity specified by STL. But STL does not technically concern itself with such things -- it makes certain time guarantees and iterator guarantees, nothing else. A std::map guarantees that the time to access a member is O(log n) in the number of members and that iteration is roughly linear. In practice, this is achieved through a tree, but you can't make that assumption.