effective STL An item focuses on the List.size () is an O (n) efficiency at that time just to note down the back look at the csdn someone in the actual project encountered a pit I recently idle to have nothing to do with the STL list related part of the good look:
Look at the reason why the STL Daniel is set to O (n):
1) size () call algorithm in distance () to get the length and empty () is to determine whether the head and tail are equal O (1) Most of the time we are judging whether the list is empty
2) Design reason: List introduced an important splice operation, at the constant level that is O (1) To complete the list of Tranfer this operation on the merge reverse sort has a great help if:
Size () do not do so tranfer cannot be O (1) completion is not O (1) then the merge and sort cannot be done efficiently and the merge and sort operations are actually more important, so size () is called on each call distance And not better O (1) so that you can divide Tranfer's constant-level operation to see the online people spit groove This place I want to understand the above design principle will not spit groove this structure.
C + + list size () things to think about