• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
I'm full of tinier men! And a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic