guys i am thinking about one sorting method,it is called sleep sort
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
int main(int c, char **v)
{
while (--c > 1 && !fork());
sleep(c = atoi(v[c]));
printf("%d\n", c);
wait(0);
return 0;
}
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
void wait ( int seconds ){
clock_t endwait;
endwait = clock () + seconds * CLOCKS_PER_SEC ;
while (clock() < endwait) {}
}
but what about fork()?
i have try following code
#include<iostream>
#include<time.h>
using namespace std;;
void wait ( int seconds ){
clock_t endwait;
endwait = clock () + seconds * CLOCKS_PER_SEC ;
while (clock() < endwait) {}
}
void Sort(int c,int a[])
{
while(--c>1)
{
wait(c=a[c]);
cout<<c<<" ";
}
}
int main()
{
int a[]={1, 3, 2, 11, 6, 4};
int c=5;
Sort(c,a);
wait(0);
return 0;
}
but it does not give me sorted output,it outputs like 6 4 1 and finishes,so please tell me how to correct it?
Here is a working implementation in C++ using Win32: