let me say that I have tree and the tree has these leaf nodes from right to left:
[ 9, 4, 6,16 ,8,19, 10,8 ], I should write function to print every second leaf node from right to left, so the output should be {4, 16 , 19 ,8 }, and ignore the rest
I wrote function but it prints all leaf nodes!
The easiest way is probably to pass an additional bool argument by reference to keep track of whether you should print the next leaf or not. Every time you reach a leaf node you flip the bool and check if you should print.
Another alternative is to instead pass a container and instead of printing you just add the leaf node values to the container, and when you have traversed the whole tree you can simply loop over the container and print every other value.