I mean in reverse sorry, essentially, find the first true element, then circularly move backwards until you find the last valid element, once the last element that is true is found by circularly reverse traversing the array, circularly go forward and push until a false is found.
I am given an array of pair of bool,int.
The array always has 4 elements. Elements that are true are circularly linked together ex:
TFFT
TTFT
FFTT
FTTT
TFFF
FTTF
These are all valid arrays that I could have.
The number they contain is not important for this (the pair second value).
What I need to do is:
only keep the true ones. But I need them to stay in the correct circular order such that the last valid true element will come first.
So for example:
If my array was:
T 1
F 2
F 3
T 4
The new array needs to be:
T 4
T 1
Another example:
If my array was:
F 1
T 2
T 3
F 4
The new array needs to be:
T 2
T 3
This is just an abstract example of the problem. The actual code is complex and hard to read. But if I know how to do this I’ll be alright.
Essentially I need to walk clockwise from the first discontinuous element to the last contiguous element.
Thanks
Edit:
By circularly linked together I mean that if the 4th and first element are true, they are not disconnected meaning they are not discontiguous, 3,4,1 is considered contiguous.
Thus if you had TFTT then I need them to be in the order of 3,4,1.
You can think of your array as containing three segments:
(If your array might not have any F elements at all, then you can handle that as a special case.)
What you want is a new array containing segment 3 followed by segment 1, with segment 2 erased.
Here’s an outline of an algorithm to do that: