Question: Implement the rotateLeft method in IntSinglyLinkedlist. It moves all elements closer to the front of the list by one space, moving the front element to


Implement the rotateLeft method in IntSinglyLinkedlist. It moves all elements closer to the front of the list by one space, moving the front element to be the last. For example, here is what it looks like to rotateLeft once. Abstract view: rotateleft() on the list [12, 7, 100) turns the list into [7, 100, 12] Box-and-arrow view: IntSinglyLinkedList Node Node head Node element 12 element 7 element 100 tail next next next size IntSinglyLinkedList Node Node head Node element 12 element 7 element 100 tail next next size Important tip: this method does not require loops or recursion! @Test public void rotateLeftiTest() { IntsinglyLinkedlist s = new IntsinglyLinkedlist(); s.rotateLeft(); S.addFirst( e: 7); s.rotateLeft(); assertEquals( expected: 7, (int) s.first()); assertEquals( expected: 7, (int) s.last()); s.rotateLeft(); assertEquals( expected: 7, (int) s.first()); assertEquals( expected: 7, (int) s.last()); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
