i got a string and i want to rotate the odd members
str "abcdef"
1 rotate
"afcbed"
second rotate
"adcfeb"
etc..
what is the algorithm for doing that..
i got a string and i want to rotate the odd members
str "abcdef"
1 rotate
"afcbed"
second rotate
"adcfeb"
etc..
what is the algorithm for doing that..
Which direction are you gonna rotate the string, left or right?
How about you come with an algorithm and surely board members will help out.
rotating to the right
the index of "f" is 5 and it needs to be on 1
the index of "d" is 3 and it needs to be on 5
the index of "b" is 1 and it needs to be on 3
so ill do copy each odd cell x to x+2 cell
and the last will be copied to cell 1
You pretty much solved it. So you can make a loop - something like
Code:for (i = 1; i < 6; i += 2) ...
It seems like your "rotation" is more of randomization. Consider using srand for that (I'm not sure how effective this function is or what's called). Since you only want one instance of each letter, if the chosen one is already chosen, get another random number until you have something different. The "ace" part is unchanged so you only need to work with the other 3.
High elevation is the best elevation. The higher, the better the view!
My computer: XP Pro SP3, 3.4 GHz i7-2600K CPU (OC'd to 4 GHz), 4 GB DDR3 RAM, X-Fi Platinum sound, GeForce 460, 1920x1440 resolution, 1250 GB HDD space, Visual C++ 2008 Express