java - homework: to circular shift an unknown sized linked list without looping over its elements more than once and without creating a duplicate list? -


i got java assignment:

i receive singly linked list head. allowed iterate on list once, , not duplicate it. receive positive integer n may bigger (unknown) list size. (the last node's 'next' field refers null) list must circular shifted n times, without duplicated operations. need return new head node.

example n=5:

1 2 3 4 5 6 7 8 9

-> turns into

6 7 8 9 1 2 3 4 5

i fail see how possible when n bigger list size.. in advance

when n bigger array size should start @ 0 again. it'd same if write:

 n=n%arraysize; 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -