Constructing a divide and conquer algorithm for Gray code (C++)