title: sleep sort in c++ 11
body: <p>guys i am  thinking about one sorting method,it is called sleep sort</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/wait.h&gt;
  
  int main(int c, char **v)
  {
      while (--c &gt; 1 &amp;&amp; !fork());
      sleep(c = atoi(v[c]));
      printf("%d\n", c);
      wait(0);
      return 0;
  }
  </code></pre>
  
  <p>i dont understand  one thing,what is fork equivalent in c++ 11?i meant new version of c++?i could write wait function like this</p>
  
  <pre><code>void wait ( int seconds ){
      clock_t endwait;
      endwait = clock () + seconds * CLOCKS_PER_SEC ;
      while (clock() &lt; endwait) {}
  }
  </code></pre>
  
  <p>but what about  fork()?
  i have try following code</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;time.h&gt;
  using namespace std;;
  
  void wait ( int seconds ){
      clock_t endwait;
      endwait = clock () + seconds * CLOCKS_PER_SEC ;
      while (clock() &lt; endwait) {}
  }
  
  void Sort(int c,int a[])
  {
      while(--c&gt;1)
      {
          wait(c=a[c]);
          cout&lt;&lt;c&lt;&lt;"  ";
      }
   }
  
  int main()
  {
      int a[]={1, 3, 2, 11, 6, 4};
      int c=5;
      Sort(c,a);
      wait(0);
  
      return 0;
  }
  </code></pre>
  
  <p>but it does not give me sorted output,it outputs like 6 4 1 and finishes,so please tell me how to  correct it?</p>