In my Java application, both of them will be compiled and run, and you will get the desired result.
myLinkedList.addLast(myLinkedList.removeFirst());
And the "rotation" in the opposite direction
myLinkedList.addFirst(myLinkedList.removeLast());
Both "rotations" require only one line of code, but I wonder if this is the right thing to do? Are there any pitfalls in this approach?
Is there a better, more reliable, less error prone way to do the same as mine above, which will require more than one line of code, and if so, explain why.
source
share