Answers for "gray c++"

C++
0

gray c++

vector <string> a;
    a={"0","1"};
    int i, j;
    for (i = 2; i < (1<<n); i = i<<1)
    {
        for (j = i-1 ; j >= 0 ; j--)
            a.push_back(a[j]);
        for (j = 0 ; j < i ; j++)
            a[j] = "0" + a[j];
        for (j = i ; j < 2*i ; j++)
            a[j] = "1" + a[j];
    }
    for (i = 0 ; i < a.size() ; i++ )
        cout << a[i] << " ";
Posted by: Guest on April-10-2021

Browse Popular Code Answers by Language