Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8536321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:38:07+00:00 2026-06-11T10:38:07+00:00

guys i am thinking about one sorting method,it is called sleep sort #include <stdlib.h>

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:38:09+00:00Added an answer on June 11, 2026 at 10:38 am

    Here is a working implementation in C++ using Win32:

    #include <windows.h>
    #include <iostream>
    
    using namespace std;
    
    DWORD threadFunc(LPVOID param)
    {
        long val = (long)param;
        Sleep((int)val * 1000);
        cout << val << " ";
        return 0;
    }
    
    int main()
    {
        HANDLE handles[6];
        int arr[] = {1, 3, 2, 11, 6, 4};
    
        for(int i = 0; i < 6; i++)
        {
            handles[i] = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&threadFunc, 
                                      (LPVOID)arr[i], 0, NULL);
        }
    
        WaitForMultipleObjects(6, handles, 1, INFINITE);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just thinking about my page titles and wondering which one to have keyword |
Hey guys, I'm at a deadlock here after thinking about this for too long.
Good morning, guys. I was just thinking about the small PHP crawler, that could
Guys, what is function called after my class loaded, where i can call self
I was thinking about some memory pool/allocation stuff I might write so I came
I'm thinking about creating a plugin for jailbroken iPhones to record audio from apps.
I was thinking about the syntax of inner joins in Oracle's SQL implementation and
I've just started using Python and I was thinking about which notation I should
I've been thinking about setting up a image grid similar to milliondollarhomepage for a
I'm thinking about writing a program that asks the user to think of an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.