0

I have one List A which always has 7 elements.

There is another List B which can have a variable size but let's assume for now it's size is 5 and it has the elements {a,b,c,d,e}. Now I need to cycle those elements of list B in the "slots" of list A left or right, always by 1 position.

So, initially List A will be {a,b,c,d,e,null,null}. If the shift is left, after 1 iteration, it should look like {b,c,d,e,null,null,a}, after 2 iterations {c,d,e,null,null,a,b} etc. If the shift is right, after 1 iteration it would be {null,a,b,c,d,e,null}, after 2 iterations {null,null,a,b,c,d,e} etc.

If the List B is greater in size than A (e.g. {a,b,c,d,e,f,g,h}), after shifting left, List A might be {b,c,d,e,f,g,h} and after shifting right, {h,a,b,c,d,e,f}.

I've spent a lot of time trying to do that using temporary variables or lists but it always fails one way or another. My C# knowledge is also pretty basic at this point. If anyone could give me some guidance, that would be great.

TomaszS
  • 153
  • 1
  • 1
  • 6
  • You should add the code that you have tried and the problem it has. – Gusman Jun 14 '20 at 18:54
  • OK the above solution was helpful, leaving this comment if anyone else comes across a similar task. I ended up just using regular List as a Queue is only good for cycling one way. I just check the direction of the shift (-1 or +1) and based on that, I am removing first element and adding it to the end or removing from the end and adding it at the beginning of my List. Then I assign values from this temporary List to the elements of List A. – TomaszS Jun 15 '20 at 07:24

0 Answers0