Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!

Oh gosh, i think it's a BUG ?!

Ken Ng
Greenhorn
Posts: 26
hi all, this post is a sequel to the message:
(anti)clockwise rotation of array elements...HELP!
Original intention of previous msg
int[] a = {1,2,3,4,5};
Rotate CLOCKWISE => 2,3,4,5,1
Rotate ANTI-CLOCKWISE => 5,1,2,3,4
--------------------------------------------------------------------------
I had posted my code for this problem. If u were to try vicken's modified version of my code(which is more readable and efficient, My (ken's) code got some error for ANTI-CLOCKWISE)
1) Inside main(),

You get,
5 1 2 3 4 (ANTI-CLOCKWISE result)
1 2 3 4 5 (CLOCKWISE result)

2) Now, modify inside main() by just interchanging the clockwise() and antiClockwise() statement,

You get
2 3 4 5 1 (CLOCKWISE result)
1 2 3 4 5 (ANTI-CLOCKWISE result)

3) Next, modify accordingly inside main() to do continous rotation

you get
Initially...1 2 3 4 5
2 3 4 5 1 (CLOCKWISE result)
1 2 3 4 5 (ANTI-CLOCKWISE result)
2 3 4 5 1 (CLOCKWISE result)
1 2 3 4 5 (ANTI-CLOCKWISE result)
2 3 4 5 1 (CLOCKWISE result)
1 2 3 4 5 (ANTI-CLOCKWISE result)
2 3 4 5 1 (CLOCKWISE result)
1 2 3 4 5 (ANTI-CLOCKWISE result)
2 3 4 5 1 (CLOCKWISE result)
1 2 3 4 5 (ANTI-CLOCKWISE result)

4) Lastly (hope u are still with me) to get around this problem, modify again,

You get,
Initially...1 2 3 4 5
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4
1 2 3 4 5
Initially...1 2 3 4 5
5 1 2 3 4
4 5 1 2 3
3 4 5 1 2
2 3 4 5 1
1 2 3 4 5
--------------------------------------------------------------------
These Demo shows 3 things.
-Both ANTI-CLOCKWISE and CLOCKWISE algorithm works!
-ANTI-CLOCKWISE works but CLOCKWISE fails and vice versa if used one after the other
-U see that 5 rotations were performed continously w/o problem for ANTICLOCKWISE case and CLOCKWISE case SEPARATELY.

CONCLUSION!
YOU CAN'T DO AN ANTI-CLOCKWISE ROTATION OF AN ARRAY BEFORE OR AFTER A CLOCKWISE ROTATION !!!
BUT YOU COULD PERFORM ONE AND ONLY ONE TYPE OF ROTATION CONTINOUSLY W/O PROBLEM

Someone PLS tell me it's not a bug and explain it.
[ March 15, 2004: Message edited by: Ken Ng ]

Vicken Karaoghlanian
Ranch Hand
Posts: 522
I have read your post three times already, and couldn�t see anything extraordinary about the code. The code is working fine as expected, there is no error, no bugs�. Nothing.
One thing you should know is that arrays are object in java; if you do a clockwise/ anticlockwise rotation you are actually changing the order of the elements in the array. You can�t expect the array remains the same after performing any of these rotations.

Ravi Srinivas
Greenhorn
Posts: 26
I havent seen your earlier post, but based on this one it does seem as if there is no bug. If you take an array, rotate it anti-clockwise once and then rotate it clockwise once you will end up with the original array.
This is also what your code shows, so I guess there is no bug.
When you said that rotating clockwise and anti-clockwise alternately doesnt work, did you expect the original array as a result or something else?