Sponsored Content
Top Forums Programming wired problem about next_permutation Post 302501861 by homeboy on Saturday 5th of March 2011 08:49:53 AM
Old 03-05-2011
wired problem about next_permutation

hello all,
If i have a vector of strings,i wanna get all possible combinations of them,for example,the elements of that vector are
"hello" "world" "!"
I thought the answer should be:
Code:
hello world !
hello ! world
world ! hello
world hello !
! hello world
! world hello

However,with the code below ,i got the result like this:
Code:
helloworld!
world!hello
worldhello!

what's the problem?
Code:
int main()
{
	string ch[] = {"hello","world","!"};
	vector<string> vec(ch,ch+3);

	do{
		vector<string>::iterator pos = vec.begin();	
		cout<<*pos<<*(pos+1)<<*(pos+2)<<endl;
	}while(next_permutation(vec.begin(),vec.end()));
	
}

---------- Post updated at 08:49 AM ---------- Previous update was at 08:02 AM ----------

Ooh.i checked the definition of next_permutation.This algorithm earranges the elements in the range [first, last) into the lexicographically next greater permutation of elements.I think it means if i want to produce all the combinations,it's better to sort the vector so that i can get the very first permutation.So,when the elements are 1,2,3 and 2,1,3,they are different,Is that right?
 

5 More Discussions You Might Find Interesting

1. Programming

wired and inactive pages

Hello How to find out wired pages and inactive pages in HP -UNIX. Bye (1 Reply)
Discussion started by: manjunath
1 Replies

2. UNIX for Advanced & Expert Users

wired pages

hi, can any body tell, what are wired pages in HP_UX. which structure contains that and plz tell the corresponding system call to get it. (1 Reply)
Discussion started by: venkat_t
1 Replies

3. What is on Your Mind?

Wired keyboard sniffing

Are we safe using the everyday wired keyboard? Although this concept is old, I had never seen an actual implementation on the matter until a few days ago. (Four ways of sniffing the electromagnetic emanations of wired keyboards currently on the market in up to 20 meters.) Check the videos at:... (2 Replies)
Discussion started by: redoubtable
2 Replies

4. Red Hat

hostapd & wired network ?

hi im using the following network with hostapd on the authenticator : Authentication server <---wired---> Authenticator(hostapd<----wired---> User (win XP with WinRadius) 1.100 -------- 1.200 , 0.13 ----- 0.12 and this is my configurations for hostapd : interface=eth1 driver=wired... (0 Replies)
Discussion started by: turner
0 Replies

5. Shell Programming and Scripting

While loop wired output issue

Hi, Wired output I am getting. Pls let me know what mistake i did on below loop script paste profile.txt names.txt | while read i j do echo >> profiles.ini echo Name=$j >> profiles.ini echo IsRelative=1 >> profiles.ini echo Path=Profiles/$j >> profiles.ini done ... (3 Replies)
Discussion started by: ranjancom2000
3 Replies
mlib_VectorReverseByteOrder(3MLIB)			    mediaLib Library Functions				mlib_VectorReverseByteOrder(3MLIB)

NAME
mlib_VectorReverseByteOrder - reverse byte order of vector SYNOPSIS
cc [ flag... ] file... -lmlib [ library... ] #include <mlib.h> mlib_status mlib_VectorReverseByteOrder(void *z, const void *x, mlib_s32 n, mlib_s32 s); DESCRIPTION
The mlib_VectorReverseByteOrder() function changes the encoding of each element from big endian to little endian, or from little endian to big endian. It copies and reverses the byte order of each element of the input vector into the output vector. PARAMETERS
The function takes the following arguments: z Pointer to the output vector. x Pointer to the input vector. n Number of elements in the vectors. s Size of elements in bytes. RETURN VALUES
The function returns MLIB_SUCCESS if successful. Otherwise it returns MLIB_FAILURE. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Interface Stability |Committed | +-----------------------------+-----------------------------+ |MT-Level |MT-Safe | +-----------------------------+-----------------------------+ SEE ALSO
mlib_VectorReverseByteOrder_Inp(3MLIB), mlib_VectorReverseByteOrder_S16(3MLIB), mlib_VectorReverseByteOrder_S16_S16(3MLIB), attributes(5) SunOS 5.11 2 Mar 2007 mlib_VectorReverseByteOrder(3MLIB)
All times are GMT -4. The time now is 01:32 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy