Thread: set, vector & list

  1. #1
    Burning in Hell! Luigi's Avatar
    Join Date
    Nov 2002
    Posts
    117

    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

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    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.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  2. urgent help please...
    By peter_hii in forum C++ Programming
    Replies: 11
    Last Post: 10-30-2006, 06:37 AM
  3. store data from ifstream and store in link list
    By peter_hii in forum C++ Programming
    Replies: 2
    Last Post: 10-26-2006, 08:50 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. compiler build error
    By KristTlove in forum C++ Programming
    Replies: 2
    Last Post: 11-30-2003, 10:16 AM