Container classes, or containers for short, manage a collection
of elements. To meet different needs, the STL provides different kinds of
containers, as shown in figure below
Figure: STL Container Types
There are two general kinds of containers:
-
Sequence containers are ordered collections in which every element has a certain position. This position depends on the time and place of the insertion, but it is independent of the value of the element. For example, if you put six elements into a collection by appending each element at the end of the actual collection, these elements are in the exact order in which you put them. The STL contains three predefined sequence container classes: vector, deque, and list.
-
Associative containers are sorted collections in which the actual position of an element depends on its value due to a certain sorting criterion. If you put six elements into a collection, their order depends only on their value. The order of insertion doesn't matter. The STL contains four predefined associative container classes: set, multiset, map, and multimap.
An associative container can be considered a special kind of sequence
container because sorted collections are ordered according to a sorting
criterion. You might expect this especially if you have used other libraries of
collection classes like those in Smalltalk or the NIHCL, in which sorted collections are derived
from ordered collections. However, note that the STL collection types are
completely distinct from each other. They have different implementations that
are not derived from each other.
The automatic sorting of elements in associative containers does not
mean that those containers are especially designed for sorting elements. You can
also sort the elements of a sequence container. The key advantage of automatic
sorting is better performance when you search elements. In particular, you can
always use a binary search, which results in logarithmic complexity rather than
linear complexity. For example, this means that for a search in a collection of
1,000 elements you need, on average, only 10 instead of 500 comparisons. Thus, automatic sorting is only
a (useful) "side effect" of the implementation of an associative container,
designed to enable better performance.
The following subsections discuss the different container classes in detail.
Among other aspects, they describe how containers are typically implemented.
Strictly speaking, the particular implementation of any container is not defined
inside the C++ standard library. However, the behavior and complexity specified
by the standard do not leave much room for variation. So, in practice, the
implementations differ only in minor details. Coming post with covers the exact behavior of the
container classes. It describes their common and individual abilities, and
member functions in detail.
Sequence Containers
The following sequence containers are predefined in the STL:-
Vectors
-
Deques
- Lists
Vectors
A vector manages its elements in a dynamic array. It enables random access,
which means you can access each element directly with the corresponding index.
Appending and removing elements at the end of the array is very fast. However, inserting an
element in the middle or at the beginning of the array takes time because all
the following elements have to be moved to make room for it while maintaining
the order. Strictly speaking,
appending elements is amortized very fast. An individual append may be
slow, when a vector has to reallocate new memory and to copy existing elements
into the new memory. However, because such reallocations are rather rare, the
operation is very fast in the long term.
The following example defines a vector for integer values, inserts six
elements, and prints the elements of the vector:
-----------------------------------------------------------------
See Also:
-----------------------------------------------------------------
See Also:
-----------------------------------------------------------------
- Complete Tutorial of C++ Template's
- Standard Template Library Tutorial
- Inter Process Communication Tutorial
- Advance Programming in C & C++
-----------------------------------------------------------------
This is a brilliant blog! I'm very happy with the comments!.. shipping containers
ReplyDeleteThanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for. shipping containers for sale toowoomba
ReplyDeleteI recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have enjoyed reading. toowoomba shipping containers
ReplyDeleteI admire what you have done here. I like the part where you say you are doing this to give back but I would assume by all the comments that this is working for you as well. toowoomba shipping containers
ReplyDeleteThank you for very usefull information.. toowoomba shipping containers
ReplyDeleteThis article gives the light in which we can observe the reality. This is very nice one and gives indepth information. Thanks for this nice article. shipping container
ReplyDeleteI admire what you have done here. I like the part where you say you are doing this to give back but I would assume by all the comments that this is working for you as well. shipping container for sale
ReplyDeleteThis is a good post. This post gives truly quality information. I’m definitely going to look into it. Really very useful tips are provided here. Thank you so much. Keep up the good works. shipping containers ballina
ReplyDeleteThanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts. shipping containers ballina
ReplyDeleteThis article gives the light in which we can observe the reality. This is very nice one and gives indepth information. Thanks for this nice article. shipping container brisbane
ReplyDeleteThis is a good post. This post gives truly quality information. I’m definitely going to look into it. Really very useful tips are provided here. Thank you so much. Keep up the good works. shipping containers brisbane
ReplyDeleteThanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts. shipping containers brisbane
ReplyDeleteThanks for posting this info. I just want to let you know that I just check out your site and I find it very interesting and informative. I can't wait to read lots of your posts. shipping container ballina
ReplyDeleteThis is a good post. This post gives truly quality information. I’m definitely going to look into it. Really very useful tips are provided here. Thank you so much. Keep up the good works. brisbane shipping containers
ReplyDeleteCool stuff you have got and you keep update all of us. brisbane shipping containers
ReplyDeleteI found this is an informative and interesting post so i think so it is very useful and knowledgeable. I would like to thank you for the efforts you have made in writing this article. shipping containers for sale cairns
ReplyDeleteThis is truly a great read for me. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work!. cairns shipping containers
ReplyDeleteThanks for sharing this quality information with us. I really enjoyed reading. Will surely going to share this URL with my friends. buy shipping container cairns
ReplyDeleteGreat things you’ve always shared with us. Just keep writing this kind of posts.The time which was wasted in traveling for tuition now it can be used for studies.Thanks shipping container cairns
ReplyDeletePositive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. shipping container gold coast
ReplyDeleteI just want to let you know that I just check out your site and I find it very interesting and informative.. shipping containers for sale gold coast
ReplyDeleteThanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for. buy shipping container cairns
ReplyDeleteI wanted to thank you for this excellent read!! I definitely loved every little bit of it. I have you bookmarked your site to check out the new stuff you post. buy shipping container cairns
ReplyDeleteI really thank you for the valuable info on this great subject and look forward to more great posts. Thanks a lot for enjoying this beauty article with me. I am appreciating it very much! Looking forward to another great article. Good luck to the author! All the best! gold coast shipping containers
ReplyDeleteThis blog is really great. The information here will surely be of some help to me. Thanks!. shipping container gold coast
ReplyDeleteI really loved reading your blog. It was very well authored and easy to understand. Unlike other blogs I have read which are really not that good.Thanks alot! shipping containers for sale gold coast
ReplyDeleteYour content is nothing short of brilliant in many ways. I think this is engaging and eye-opening material. Thank you so much for caring about your content and your readers. shipping containers gold coast
ReplyDeleteI have a hard time describing my thoughts on content, but I really felt I should here. Your article is really great. I like the way you wrote this information. buy shipping container gold coast
ReplyDeleteYou have a good point here!I totally agree with what you have said!!Thanks for sharing your views...hope more people will read this article!!! abc container hire
ReplyDeleteThis is a brilliant blog! I'm very happy with the comments!.. abc containers
ReplyDeleteI really loved reading your blog. It was very well authored and easy to understand. Unlike other blogs I have read which are really not that good.Thanks alot! port shipping container
ReplyDeleteI recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have enjoyed reading. 40ft shipping container
ReplyDeleteYou’ve got some interesting points in this article. I would have never considered any of these if I didn’t come across this. Thanks!. container sales containers for sale
ReplyDeleteThis is a good post. This post gives truly quality information. I’m definitely going to look into it. Really very useful tips are provided here. Thank you so much. Keep up the good works. sea container
ReplyDeleteI have read a few of the articles on your website now, and I really like your style of blogging. I added it to my favorites blog site list and will be checking back soon. Please check out my site as well and let me know what you think. container sales containers for sale
ReplyDeleteYour work is very good and I appreciate you and hopping for some more informative posts. Thank you for sharing great information to us. sea container
ReplyDeleteI really impressed after read this because of some quality work and informative thoughts . I just wanna say thanks for the writer and wish you all the best for coming!. 20ft container sales
ReplyDeleteNice to be visiting your blog again, it has been months for me. Well this article that i’ve been waited for so long. I need this article to complete my assignment in the college, and it has same topic with your article. Thanks, great share. 20ft container for sale
ReplyDeleteThank you for very usefull information.. 20ft container for sale
ReplyDeleteYou’ve got some interesting points in this article. I would have never considered any of these if I didn’t come across this. Thanks!. abc containers
ReplyDeleteThis is a smart blog. I mean it. You have so much knowledge about this issue, and so much passion. You also know how to make people rally behind it, obviously from the responses. abc container hire
ReplyDeleteThis is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post. port shipping container
ReplyDeleteThis is a brilliant blog! I'm very happy with the comments!.. 20ft container
ReplyDeleteI never thought making money online could be this simple. TunePat Amazon Music Converter Crack Download
ReplyDeleteI've never seen anything like this. Join now and see for yourself! https://cyberspc.com/gilisoft-video-drm-protection-crack/
ReplyDelete