Best stl container to use in MY design

This is a discussion on Best stl container to use in MY design within the C++ Programming forums, part of the General Programming Boards category; What would be the best stl container to use for designing a markov chain...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    118

    Best stl container to use in MY design

    What would be the best stl container to use for designing a markov chain

  2. #2
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,235
    std::map<T, std::vector<std:: pair<double, T> > > where T is a type representing a state, ought to do the trick
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,198
    Your question, as asked, does not even make sense.

    There is no relationship between a STL container (generally contains objects with distinct values that may, or may not, be unique in the container) and a markov chain (a system with the markov property, in which the next state of the system is determined by the current state.

    If you want some representation of the sequence of states of a markov chain, then brewbuck's approach might be the trick.
    Right 98% of the time, and don't care about the other 3%.

  4. #4
    Registered User
    Join Date
    Nov 2011
    Posts
    118
    Quote Originally Posted by brewbuck View Post
    std::map<T, std::vector<std:: pair<double, T> > > where T is a type representing a state, ought to do the trick
    What about this

    Code:
        multimap<vector<string>,string  > prefixandsuffix;

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Which container do you think would be best? Research about the various container types should lead you to a best answer and/or a mix of containers that will best suit your needs. Most of the time there is not one magic container that does the trick. You may need to use several different types of containers in order to do what you want.

    And if you do use brewbuck's example save yourself some typing and typedef the vector that is acting as the value in the key,value pair as well as the map itself. It not only serves to save typing (and thus possible errors) it also makes the code a bit cleaner and thus more readable.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Looking for appropriate container
    By Elysia in forum C++ Programming
    Replies: 20
    Last Post: 07-27-2010, 04:51 PM
  2. container
    By lopezA in forum C++ Programming
    Replies: 5
    Last Post: 12-04-2007, 10:10 AM
  3. Replies: 1
    Last Post: 01-23-2006, 06:12 PM
  4. Replies: 4
    Last Post: 03-21-2004, 02:34 PM
  5. I/O using a STL container
    By LA Mills in forum C++ Programming
    Replies: 5
    Last Post: 04-20-2003, 12:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21