Backtracking: Printing Binary

#include <iostream> #include <string> using std::cout; using std::endl; void printBinary(int digits){ printBinaryHelper(digits, ""); } void printBinaryHelper(int digits, string s){ if (digits == 0) cout << s << endl; else { printBinaryHelper(digits-1, "0"+s); printBinaryHelper(digits-1, "1"+s); } } int main() { printBinary(3); return 0; }
What is choose explore unchoose...

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.