Question: WRITTTEN IN SCHEME Shift-left and Shift-right functions Write functions shiftLeft and shiftRight that take a single argument that is assumed to be a list, possibly
WRITTTEN IN SCHEME
Shift-left and Shift-right functions
Write functions shiftLeft and shiftRight that take a single argument that is assumed to be a list, possibly empty. shiftLeft returns a new list like its argument but with first element moved to the end of the list. shiftRight returns a new list with the last element moved to the front.
Here are some examples:
> (shift-left '(1 2 3)) (2 3 1) > (shift-left '(1)) (1) > (shift-left '()) () > (shift-left (shift-left '(1 2 3))) (3 1 2) > (shift-right '(1 2 3)) (3 1 2) > (shift-right '(1)) (1) > (shift-right '()) () > (shift-right (shift-right '(a b c))) (b c a)
Hints: There are many ways to implement these. shiftLeft should be fairly straight-forward, but shiftRight may be a bit tricky. If you get stuck, consider using the reverse function in scheme, which takes a list and returns the same list in reverse order
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
