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 8444081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:18:46+00:00 2026-06-10T09:18:46+00:00

Instead of The ELEMENTS being 25 is there a way to randomly generate a

  • 0

Instead of The ELEMENTS being 25 is there a way to randomly generate a large array of elements….10000, 100000, or even 1000000 elements and then use my insertion sort algorithms. I am trying to have a large array of elements and use insertion sort to put them in order and then also in reverse order. Next I used clock() in the time.h file to figure out the run time of each algorithm. I am trying to test with a large amount of numbers.

#define ELEMENTS 25

void insertion_sort(int x[],int length);
void insertion_sort_reverse(int x[],int length);

int main()
{
  clock_t tStart = clock();
  int B[ELEMENTS]={4,2,5,6,1,3,17,14,67,45,32,66,88,
               78,69,92,93,21,25,23,71,61,59,60,30};
  int x;

  cout<<"Not Sorted: "<<endl;
  for(x=0;x<ELEMENTS;x++)
       cout<<B[x]<<endl;

   insertion_sort(B,ELEMENTS);
   cout <<"Sorted Normal: "<<endl;
  for(x=0;x<ELEMENTS;x++)
       cout<< B[x] <<endl;

  insertion_sort_reverse(B,ELEMENTS);
  cout <<"Sorted Reverse: "<<endl;
  for(x=0;x<ELEMENTS;x++)
       cout<< B[x] <<endl;

  double seconds = clock() / double(CLK_TCK);
  cout << "This program has been running for " << seconds << " seconds." << endl;
  system("pause");
  return 0;
}
  • 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-10T09:18:48+00:00Added an answer on June 10, 2026 at 9:18 am
    #include <random>     // mt19937 and uniform_int_distribution
    #include <algorithm>  // generate
    #include <vector>     // vector
    #include <iterator>   // begin, end, and ostream_iterator
    #include <functional> // bind
    #include <iostream>   // cout
    
    std::vector<int> create_random_data(int n) {
      std::random_device r;
      std::seed_seq      seed{r(), r(), r(), r(), r(), r(), r(), r()};
      std::mt19937       eng(seed); // a source of random data
    
      std::uniform_int_distribution<int> dist;
      std::vector<int> v(n);
    
      generate(begin(v), end(v), bind(dist, eng));
      return v;
    }
    
    int main() {
      auto random_data = create_random_data(100000);
    
      std::cout << "unsorted: ";
      copy(begin(random_data), end(random_data),
           std::ostream_iterator<int>(std::cout, "\n"));
    }
    

    generate is a generic algorithm that fills a range with values generated by a functor. In this case we provide it with a functor that uses our source of random data to produce random numbers, and we provide a range corresponding to a container, which we can use after generate fills it with data.

    • std::generate()
    • std::uniform_int_distribution
    • std::mt19937

    We’re using std::mt19937 and std::uniform_int_distribution, standard C++ facilities as of C++11 (and available in VS2010), to create random numbers instead of the older std::rand() and std::srand() because the newer method is easier to use correctly, higher quality and more flexible.


    If you’re using VS2012 or higher then the C++11 time library is available.

    #include <chrono>
    
    int main() {
      using std::chrono::high_resolution_clock;
      using std::chrono::duration_cast;
      using std::chrono::nanoseconds;
    
      auto start = high_resolution_clock::now();
    
      // ...
    
      auto end = high_resolution_clock::now();
    
      std::cout << duration_cast<nanoseconds>(end - start).count() << "ns\n";
    }
    
    • <chrono>
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to use prototype instead of innerHTML while assigning the values to the elements
Is there a way to detect if the browser has subpixel precision for elements
Is there a way to tell the XmlSerializer to update the xml element instead
Instead of absolutely positioning (I have to do that, don't ask why) elements over
I'm not looking for an action to call when hovering, but instead a way
Is there any additional advantage of using jQuery UI Position , instead of CSS,
Instead of using the system.xml to create groups and sections in a static way
I want replace a(or each) element(number) instead another element(number) in a class while running
Instead of individually calling $(#item).removeClass() for every single class an element might have, is
How can I return null instead of a 'undefined' from a select element. Basically

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.