利用递归算法生成格雷码
#include
#include
#include
#include
std::stack<:string> result;
static int count;
void generator() {
count--;
if (count > 0) {
generator();
std::stack<:string> newResult;
int c = 0;
while(!result.empty()) {
std::string newA, newB;
newA = result.top();
result.pop();
if (!c) {
newB = newA + "0";
newResult.push(newB);
newB = newA + "1";
newResult.push(newB);
c = 1;
} else {
newB = newA + "1";
newResult.push(newB);
newB = newA + "0";
newResult.push(newB);
c = 0;
}
}
if (count % 2 == 0) {
while(!newResult.empt