tungggg

Generate all binary string 1-> N using queue

Mar 18th, 2022 (edited)
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define pub push_back
  5. string s[10];
  6. int cnt=0;
  7.  
  8. void init (){
  9.     queue < string > q;
  10.     q.push("1");
  11.     cnt ++ ;
  12.    
  13.     while ( cnt != 10 ){
  14.         string get= q.front();
  15.         q.pop();
  16.         s[cnt] = get ;
  17.         cout<<get<<" ";
  18.         string first = get+"0";
  19.         string second = get +"1";
  20.         q.push(first);
  21.         q.push(second);
  22.         cnt++;
  23.     }
  24.    
  25. }
  26.  
  27. int main(){
  28.     init ();
  29.     return 0;
  30. }
Add Comment
Please, Sign In to add comment