I can push_back each permutated set into a vector or list

  • Thread starter Thread starter Vance
  • Start date Start date
  • Tags Tags
    List Set Vector
Click For Summary

Discussion Overview

The discussion revolves around how to store each permutation of a character array into a vector or list in C++. Participants are exploring the use of the Standard Template Library (STL) for this purpose and addressing issues related to code implementation and syntax.

Discussion Character

  • Technical explanation
  • Homework-related
  • Debate/contested

Main Points Raised

  • One participant presents a code snippet attempting to generate permutations of a character array and seeks advice on storing these permutations in a vector or list.
  • Another participant criticizes the use of "std::" in the code and suggests using "using namespace std;" for cleaner code.
  • A participant points out a mistake regarding the type passed to ostream_iterator, indicating it should be "char" instead of "int" and emphasizes the need for including necessary headers like and .
  • One participant clarifies that their main issue is not just about generating permutations but specifically about storing each permuted subset as an element in a vector or list.
  • Another participant suggests creating an object to hold a permutation and then building a container of those objects.
  • A later reply reiterates the suggestion to use a list or vector without implying the need to create a custom container class.

Areas of Agreement / Disagreement

Participants express varying opinions on code style and implementation details, with no consensus on the best approach to store permutations. The discussion remains unresolved regarding the specific implementation steps.

Contextual Notes

Participants mention dependencies on compiler behavior and the necessity of including specific libraries, indicating potential limitations in the code's portability and functionality.

Vance
Messages
180
Reaction score
0
Here is the code...
PHP:
int main(){
	char a[]={'m','i','s','o'};
	do{
		std::copy(a,a+4,std::ostream_iterator<int>(std::count, " "));
		std::count<<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:
Computer science news on Phys.org
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...
 
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
 
Dduardo's link does do it using the STL...

Anyways:

holding it as an element in a vector or a list

You simply need to use/make an object that can hold a permutation, and build a container of those objects.
 
Hurkyl said:
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.
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
 
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.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 66 ·
3
Replies
66
Views
6K
  • · Replies 75 ·
3
Replies
75
Views
7K
Replies
1
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
5
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 89 ·
3
Replies
89
Views
6K
  • · Replies 4 ·
Replies
4
Views
4K