-
set, vector & list
Hi.. Im kinda new to programing and Im having trouble with some container...
understanding what they really do and how to initialize them..
I know that long, double and int are all numbers
char & char[] are letters..
but for set, vector and list..
Im not sure.
I suppose list contains a list but how u initialize it?
and for set totally cluless what that is..
vector ... well I did some physics in school..
we learned about vector which expressed a motion..
Is that it? (I kinda doubt it..)
Also if u have links where i could find more info on those same container could help cause I have hard time finding topics related to set especially..
thx in advance..
Luigi
-
Well, a board search is a great start. :)Also here.
The whole idea of a container is not having to initialize it, and for the most part, you can assume that is true. A container allows you to abstract your problem better, and provide you with the means to do so in the most effective way. In the days of C, even the most powerful data structures relied on initialization procedures. With C++, most of this is taken care of behind the scenes within constructors. So first decide what sort of container you need. Then learn the member functions and how to use them. Read all the documentation. Enjoy.
-
set, vector, and list are examples of containers. They each hold a group of something. The only proviso is the group of whatever all has to be of the same whatever. Therefore you can have a set/vector/list of ints or doubles or char or strings or pairs or whatever user defined class/object you desire, but you can't store ints and strings in the same container.
Some containers have restrictions. For example, to use a set the objects must be able to be placed in order somehow (the default is the must be orderable using the < operator but you can change the ordering function if you wish).
The containers also differ in how you use them. For example, vectors allow random access, sets and lists don't. Stacks are FILO whereas queues are FIFO, etc.
On the other hand, many of the methods in the Standard Template Library (a common source for basic containers) are the same/similar throughout the container spectrum so the learning curve is accelerated if you use that source. You can write code for your own container, too, of course.
Here's a list of common containers:
//containers in common use in C/C++
array
C style string
list
//containers in the STL of C++
//there is code for all of these in C, too, but it isn't standardized
//like it is for C++
vector
list
stack
queue
deque
set
multiset
map
multimap
tree