Last active
June 28, 2018 14:56
-
-
Save sreeprasad/9e814cdc6eb3e2ee41ec27445d847c93 to your computer and use it in GitHub Desktop.
all subsets of set
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void generateSubset(char* array) { | |
int N = strlen(array); | |
int range = (1<<N)-1; | |
for (int i=0;i<range;i++) { | |
checkBitSetAndPrint(array, i); | |
} | |
} | |
void checkBitSetAndPrint(char* array, int N){ | |
int i=0; | |
while (N>0) { | |
if (N&1) { // check if last bit is set | |
cout<<a[i]; // print ith index only if last bit is set | |
} | |
N=N>>1; | |
i++; | |
} | |
cout<<endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment