以下C++代码实现 n 位的格雷码,则横线上应填写( )。

sy222580 单选题 共 个子题
#include <iostream>
#include <vector>
#include <string>
using namespace std;
// 生成 n 位的格雷码
vector<string> generate_graycode(int n) {
    vector<string> graycode_list;
    if (n <= 0) {
        return graycode_list;
    }

    // 初始1位格雷码
    graycode_list.push_back("0");
    graycode_list.push_back("1");

    // 迭代生成 n 位的格雷码
    for (int i = 2; i <= n; i++) {
        int current_size = graycode_list.size();

        for (int j = current_size - 1; j >= 0; j--) {
            graycode_list.push_back("1" + graycode_list[j]);
        }

        for (int j = 0; j < current_size; j++) {
            ———————————————————————— // 在此处填入代码
        }
    }

    return graycode_list;
}
A

graycode_list.push_back("0" + graycode_list[j]);

B

graycode_list[j] = "0" + graycode_list[j];

C

graycode_list.push_back("1" + graycode_list[j]);

D

graycode_list[j] = "1" + graycode_list[j];

正在加载题目数据…
已答 /
子题
该题型需在试卷/作业中作答,单题练习暂不支持
答案解析
讨论
发布
登录后参与讨论 立即登录
发布讨论需先绑定并验证手机号 去绑定手机号
加载中…
我
我
回复 @
回复 @
发送
还没有人讨论,来发表第一条吧