Click here to Skip to main content
11,796,275 members (77,364 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C++ C C#
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 11-Feb-13 17:29pm
Edited 11-Feb-13 18:35pm
Sergey Alexandrovich Kryukov at 11-Feb-13 23:52pm
What do you mean "with key"? Transposition is one of the simplest operations, just do it by definition.
Edo Tzumer at 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 at 12-Feb-13 1:15am
Sorry, I don't understand what are your talking about, perhaps I don't know this term. A definition?
Edo Tzumer at 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 at 12-Feb-13 2:08am
Is that called 'transposition'? Ah, in cycles... OK, thank you. And where is the "key" then?
Edo Tzumer at 12-Feb-13 2:34am
The Key is the field you compare, in my example its just the numbers themselves.
Sergey Alexandrovich Kryukov at 12-Feb-13 11:16am
OK, thanks...
Sergey Alexandrovich Kryukov at 11-Feb-13 23:56pm
By the way, please stop posting "solutions" when your posts are not solution. All you can get is just abuse reports; and such reports can cause cancellation of your account. In case of heavy abuse, it happens.

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

  Print Answers RSS
0 Maciej Los 460
1 Abhinav S 368
2 OriginalGriff 340
3 CPallini 269
4 Sergey Alexandrovich Kryukov 252
0 OriginalGriff 2,012
1 Maciej Los 1,615
2 KrunalRohit 1,310
3 CPallini 1,015
4 Richard MacCutchan 828

Advertise | Privacy | Mobile
Web04 | 2.8.151002.1 | Last Updated 12 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100