algorithm concept

Hello forum,

I have a 2D array make of std::vector and I want to print out the contents in a certain patterns. There are two pattern to access the each row of the 2D array.

1. Each row is read in the forward manner.
2. Each row is read in the reverse manner.

Each of the above pattern is chosen at random at the beginning and then they alternates until all the rows are accessed.

I have encapsulated each of the read pattern inside a function. But I am not sure how to choose each of the function alternately.

Some suggestion is earnestly requested.

Thanks
Why not use a for loop and just check if the loop index is even or odd?
Or toggle a bool:
1
2
3
4
5
bool goForward = true;
...
if (goForward) forwardPrint();
else backwardPrint();
goForward = !goForward;

Topic archived. No new replies allowed.