title: Sorting an array diagonally
body: <p>I've looked up some websites but I couldn't find an answer to my problem.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>#include "stdafx.h"
  #include &lt;iostream&gt;
  #include &lt;math.h&gt;
  #include &lt;time.h&gt;
  #include&lt;iomanip&gt;
  #include&lt;array&gt;
  #include &lt;algorithm&gt;
  
  using namespace std;
  const int AS = 6;
  int filling(void);
  void printing(int[AS][AS]);
  int forsorting(int[][AS], int);
  
  
  int main()
  
  {
      int funny = 0;
      int timpa = 0;
      int counter = 0;
      int Array[AS][AS];
      srand(time(0));
  
      for (int i = 0; i&lt;AS; i++)
      {
          for (int j = 0; j&lt;AS; j++)
              Array[i][j] = filling();
      }
  
      cout &lt;&lt; "The unsorted array is" &lt;&lt; endl &lt;&lt; endl;
  
      printing(Array);
  
  
      cout &lt;&lt; "The sorted array is" &lt;&lt; endl &lt;&lt; endl;
  
  
  
      for (int il = 0; il&lt;AS; il++)
      {
          for (int elle = 0; elle&lt;AS; elle++)
              Array[il][elle] =forsorting(Array, funny);
  
          printing(Array);
  
      }
  
      system("PAUSE");
  
  
      return 0;
  
  }
  
  int filling(void)
  {
      int kira;
      kira = rand() % 87 + 12;
      return kira;
  }
  
  
  void printing(int Array[AS][AS])
  {
      int counter = 0;
      for (int i = 0; i&lt;AS; i++)
      {
          for (int j = 0; j&lt;AS; j++)
          {
              cout &lt;&lt; setw(5) &lt;&lt; Array[i][j];
              counter++;
              if (counter%AS == 0)
                  cout &lt;&lt; endl &lt;&lt; endl;
          }
      }
  }
  
  int forsorting(int Array[AS][AS], int funny)
  {
      int c, tmp, x;
      int dice = 0;
      int Brray[AS*AS];
      int timpa = 0;
      int super = 0;
  
  
      //Transofrming Array[][] into Brray[]
      for (int i = 0; i &lt; AS; i++)
      {
          for (int k = 0; k &lt; AS; k++)
          {
              Brray[timpa] = Array[i][k];
              timpa++;
          }
      }
  
  
      //Bubble sorting in Brray[]
  
      for (int passer = 1; passer &lt;= AS-1; passer++)
      {
          for (int timon = 1; timon &lt;= AS-1; timon++)
          {
              if (Brray[timpa]&gt;Brray[timpa + 1])
              {
                  super = Brray[timpa];
                  Brray[timpa] = Brray[timpa + 1];
                  Brray[timpa + 1] = super;
              }
          }
      }
  
      //Transforming Brray[] into Array[][]
  
      for (int e = 0; e&lt;AS; e++)
      {
          for (int d = 0; d&lt;AS; d++)
          {
              Brray[dice] = Array[e][d];
  
              dice++;
          }
      }
  
      ***There's a part missing here***
  
  
  }
  </code></pre>
  
  <p>What I have to do is, write a program using 3 functions. </p>
  
  <ul>
  <li>The 1st function would fill my 2D array randomly (no problem with this part)</li>
  <li>the 2nd function would print the unsorted array on the screen (no problem with this part)</li>
  <li>and the 3rd function would sort my array diagonally as shown in this picture: </li>
  </ul>
  
  <p><img src="https://i.stack.imgur.com/MAeLp.jpg" alt="Sample"></p>
  
  <p>Then I need to call the 2nd function to print the sorted array. My problem is with the 3rd function I turned my 2D array into a 1D array and sorted it using Bubble sorting, but what I can't do is turn it back into a 2D array diagonaly sorted.</p>