Click here to Skip to main content
16,018,417 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
how to shuffle the elements in an array using a key in such a way that no two adjacent elements should appear adjacently in shuffled array.From the shuffled array i need original array using only the same key.
Posted
Updated 11-Feb-13 18:35pm
v3
Comments
Sergey Alexandrovich Kryukov 11-Feb-13 23:52pm    
What do you mean "with key"? Transposition is one of the simplest operations, just do it by definition.
—SA
Joezer BH 12-Feb-13 1:06am    
Actually I think it's a nice question - it's not a simple transposition, making sure that two adjacent elements are now not adjacent.
Sergey Alexandrovich Kryukov 12-Feb-13 1:15am    
Sorry, I don't understand what are your talking about, perhaps I don't know this term. A definition?
—SA
Joezer BH 12-Feb-13 1:30am    
*If I understand manuthebos correctly*

Given an array: { 1, 2, 3, 4, 5}
you need to shuffle the array so that:
- 1 is not near 2
- 2 is not near 3 (and not 1 of course)
- ...

e.g. { 3, 1, 4, 2, 5} is a good shuffle
Sergey Alexandrovich Kryukov 12-Feb-13 2:08am    
Is that called 'transposition'? Ah, in cycles... OK, thank you. And where is the "key" then?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900