1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

I can push_back each permutated set into a vector or list

  1. Jul 30, 2004 #1
    Here is the code...
    PHP:
    int main(){
        char a[]={'m','i','s','o'};
        do{
            std::copy(a,a+4,std::ostream_iterator<int>(std::cout, " "));
            std::cout<<std::endl;
        }while(std::next_permutation(a,a+4));
        return 1234567890;
    }
    Can you tell me how I can push_back each permutated set into a vector or list or anything ?
    I would like to use each of them then...
    Do you have any ideas or instructions ?

    (Edit) I am sorry, I change int array into char one and my first question should be how to make a string from chars above, I would first change them into "miso"- a string rather than just a char-array

    Thanks
    Nn
     
    Last edited: Jul 30, 2004
  2. jcsd
  3. Jul 30, 2004 #2

    dduardo

    User Avatar
    Staff Emeritus

  4. Jul 30, 2004 #3
    I am sorry, I forgot to change the type passed in ostream_iterator class which should be "char" instead of int.
    :shy: I am still a newie in STL :shy:, as far as I know, it depends on the compilers people use to make that code compile with or without include<iterator>. Don't forget to include<algorithm> also or permutation won't agree to go the way you want...

    Thanks dduardo for the link, I know my problem can be easily solve with C but I like to do it with C++/STL better...
     
  5. Jul 30, 2004 #4
    By the way, my problem is not exactly about permutation but about grabbing each of
    permutated subset, holding it as an element in a vector or a list at which I am getting stuck...

    Any ideas, instructions would as always appreciated...
    Again Thanks a lot
     
  6. Jul 30, 2004 #5

    Hurkyl

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Dduardo's link does do it using the STL...

    Anyways:

    You simply need to use/make an object that can hold a permutation, and build a container of those objects.
     
  7. Jul 30, 2004 #6
    I am sorry, i didn't come there to have a look...

    Can you please be more specific about building a container, i am new and have never done anything like that before?

    Thanks
     
  8. Jul 31, 2004 #7

    Hurkyl

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    I meant just use list or vector, as in "build a vector out of those objects"; I didn't mean to suggest you should write your own container class for this problem.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: I can push_back each permutated set into a vector or list
  1. Can i find answers? (Replies: 4)

  2. I can help (Replies: 5)

  3. How i can hack ? (Replies: 29)

Loading...