Collections: Difference between revisions

m
Spelling/grammar/aesthetics.
No edit summary
m (Spelling/grammar/aesthetics.)
Line 4:
 
=={{header|C++}}==
C++ has a range of different collections optimized for different use cases. Note that in C++, objects of user-defined types are mostly treated just like objects of built-in types; especially there's no different treatment for copllectionscollections. Thus all collections can simply be demonstrated with the built-in type <tt>int</tt>. For user-defined types, just replace int with the user-defined type. Any type which goes into a collection must be copyable and assignable (which in general is automatically the case unless you explicitly disallow it).
 
Note however that C++ collections store ''copies'' of the objects given to them, so you'll lose any polymorphic behaviour. If you need polymorphism, use a collection of pointers (or smart pointers like boost::shared_ptr).
 
===vector===
A vector is basically a resizeableresizable array. It is optimized for adding/removing elements on the end, and fast access to elements anywhere. Inserting elements at the beginning or in the middle is possible, but in general inefficient.
 
#include <vector>
Line 203:
</pre>
 
In addition Python classes support a number of methods allowing them to implement indexing, slicing, and attribute management features as collections. Thus many modules in the Python standard libraries allow one to treat files contents, databases, and other data using the same syntax as the native collection types. Some Python modules (such as Numeric and NumPy) provide low-level implementations of additional collections (such as efficient n-dimensional arrays).
 
=={{header|Raven}}==
Anonymous user