title: Find largest number formed with numbers of an array
body: <p>The task is to find the largest number formed with the numbers of an array. For example:</p>
  <p>input: 7, 56, 94, 1
  output: 947561</p>
  <p>In the code, I compare ab and ba, and then sort the numbers using bubble sort.</p>
  <p>My code works for 80% test cases, but I cannot find the mistake. Where or which case haven't I taken into account? Thanks in advance.</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;cmath&gt;
  using namespace std;
  
  typedef long long int ll;
  
  ll len(ll n){
  
      ll l = 0;
      while (n &gt; 0){
  
          n /= 10;
          l++;
      }
  return l;
  }
  
  ll concade(ll a, ll b){
  
      ll con = a * pow(10, len(b)) + b;
  return con;
  }
  
  
  void swap(ll *xp, ll *yp){
  
      ll temp = *xp;
      *xp = *yp;
      *yp = temp;
  }
  
  void bubble_sort(ll arr[], ll n){
  
      ll i, j;
      for (i = 0; i &lt; n - 1; i++){
          for (j = 0; j &lt; n-i-1; j++){
  
              if (arr[j] == 0 &amp;&amp; arr[j+1] != 0)
                  swap(arr[j], arr[j+1]);
  
              if (concade(arr[j], arr[j+1]) &lt; concade(arr[j+1], arr[j]))
                  swap(arr[j], arr[j+1]);
          }
      }
  }
  
  int main(){
  
      ll n;
      while (cin &gt;&gt; n){
  
          if (n == 0) 
              break;
  
          ll arr[1000000];
          for(ll i = 0; i &lt; n; i++){
  
              ll x;
              cin &gt;&gt; x;
              arr[i] = x;
          }
          bubble_sort(arr, n);
          for (ll i = 0; i &lt; n; i++)
              cout &lt;&lt; arr[i];
          cout &lt;&lt; endl;
      }
  }
  </code></pre>