title: C++, moving a NaN to the end of the array, when output
body: <p>So, i've made a program which is able to sort arrays, and i'm trying to sort an array containing double FP's, including 2-3 random ones i enter, pos inf, neg inf and a single NaN. so for this purpose i wish to sort the NaN.
  So my code works, however when trying to sort the NaN, i'm unable to do so. What i'd like to do is sort it to the end, or have it put at the end of the sorted array. Is there anyway I can actually do this? Thanks in advance!!! code is as follows:</p>
  
  <pre><code>int main()
  {
  int start_s = clock();
  int n, k = 4, j; // k is number of elements
  double x = -0.0;
  double i = 0;
  double swap = 0;//used in the function as a place holder and used for swapping between other variables
  double a[100] = { (1/x) + (1/i), 2.3, 1/x *0, 1/i };//array of double elements // 1/i * 0 is NaN
  //(1 / i) * 0
  
  
  for (n = 0; n &lt; (k - 1); n++) // for loop consists of variables and statements in order to arrange contents of array
  {
    for (j = 0; j &lt; k - n - 1; j++)
      {
        if (a[j] &gt; a[j + 1])
  
          {
          swap = a[j];
          a[j] = a[j + 1];
          a[j + 1] = swap;
  
          }
      }
  }
  
  cout &lt;&lt; "The list of sorted elements within the array, is: " &lt;&lt; endl; /* Output message to user */
  for (int i = 0; i &lt; k; i++)// Loop up to number of elements within the array
  {
      cout &lt;&lt; a[i] &lt;&lt; " ";/* Output contents of array */
  }
  cout &lt;&lt; endl; //new line
  
  int stop_s = clock();
  cout &lt;&lt; "The execution time of this sort, is equal to: " &lt;&lt; (stop_s - start_s) / double(CLOCKS_PER_SEC) * 1000 &lt;&lt; " milliseconds" &lt;&lt; endl;
  
  
  
  return 0; 
  </code></pre>