title: c++ printing indexes and sorting arrays
body: <p>I need help with writing a function called <code>swap</code> that sorts the elements of an array in order from highest to lowest values where they descend and ascend. A particular thing about this function is that swap does NOT re-arrange elements in the array so it just uses a second array of indexes for the elements in the original array and then swap sorts the second array based on the values in the original array. A sorted version of the original array can then be produced with these sorted indexes. You can declare and initialize the original array without any user input. For example,</p>
  
  <pre><code>int arr[10] = {1, 5, 22, 14, 6, -5, 7, 9, 12, 15 };
  </code></pre>
  
  <p>Header of the function swap must be as shown below:</p>
  
  <pre><code>void swap(int array[],int swapedIndexes [], int size, char mode)
  </code></pre>
  
  <p>When mode is <code>'a'</code>, the function sorts the array in the ascending order, and when mode is <code>'d'</code>, the function sorts it in the descending order.</p>
  
  <p>Example:</p>
  
  <pre><code>int array[5]={2, 4,0,-5,3};
  int sortedIndexes[5];
  sortMe(array,sortedIndexes, 5, 'a');
  </code></pre>
  
  <p>here is another example of how it should be with the indexes:
  If I have <code>int number[] = {32,92,11,72};</code></p>
  
  <p>Example:
  Before
  Numbers: 32 91 11 72
  Indexes: 0 1 2 3</p>
  
  <p>After
  Numbers: 11 32 72 91
  Indexes: 2 0 3 1</p>
  
  <p>=====================================</p>
  
  <p>If your function re-arranges the elements in the array array, it is wrong.
  If you initialize the array sortedIndexes in the function main, it is wrong
  The function must sort arrays of any sizes; otherwise, its wrong.
  If you change the header of the function swap in any way, also wrong.</p>
  
  <p>So...Can somebody please show me how to print out the indexes of the array for this?? Can you please provide a code or something? I'm not sure how to use the second array of int swappedindexes; ??? This is where I am having the most problems.So far I have a simple swap code.</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int main() {
    int a[10], swap;
    for ( int i = 0; i &lt; 10; ++i )
      cin &gt;&gt; a[i];
    for ( int i = 0; i &lt; 10; ++i ) {
      for ( int j = i; j &lt; 10; ++j ){
        if( a[j] &gt; a[i] ) {
          swap = a[i];
          a[i] = a[j];
         a[j] = swap;
        }
      }
    }
  
    for ( int i = 0; i &lt; 10; ++i )
      cout &lt;&lt; a[i] &lt;&lt; " ";
    return 0;
  }
  </code></pre>