Dear All,

Was wondering if there is any way of generating the next values in an array to compute an np-complete system? Ok I know that sounds confusing but this is how it goes:
Say you have array[4]
First Array is : 1 2 3 4
Second Array: 1 2 4 3
Carries on like: 1 3 2 4; 1 3 4 2; 1 4 2 3; 1 4 3 2
e.g.
Arrays: 123456
111111
223344
342423
434232
It’s real easy to draw out but was hoping there is a function, STL or something that can generate the next array from what the previous one was. I do know more or less how I will have to code it if there isn’t a function but really not looking forward to that. It will have something to do with Nested Recursive functions :(
Thanks in advance

Recommended Answers

All 2 Replies

the function(s) next_permutation in <algorithm> would generate the next permutation. you could call that repeatedly.

Cool thank you was looking for exactly that and it works perfectly.

Thank you very very much

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.