• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C++, increasing/decreasing integer list sequence

legcramp

Golden Member
Hi there, I am making a sort program (insert sort) that takes a vector list of random, increasing, and decreasing integers. I got the random list working with the rand() command which was pretty easy, but I am having a hard time getting the list to have a pre-sorted increasing and another list with decreasing order.

(I am basically going to compare the work done / cpu clock tick between the three sequences after I get all three running)

I mean I can make a list with 20000 numbers in there and pass it into the vector but that would take forever.

Here's my random list that works great:

Code:
 srand(time(0));
    int n = 20000;
    int nums[n];
    
    for (int i=0; i<n; i++){
        nums[i]=rand()%100;
        cout<<nums[i]<<" ";

Any help is appreciated for modifying this to have an increasing and/or decreasing integer sequence instead.
 
Jeez, yeah that was it, how embarassing LOL.

I don't know why I was using nums = i++ when it was already declared here:

for (int i=0; i<n; i++)

Thanks a lot!
 
Code:
 srand(time(0));
    int n = 20000;
    [b]int nums[] = new int[n]; [/b]
    
    for (int i=0; i<n; i++){
        nums[i]=rand()%100;
        cout<<nums[i]<<" ";

    [b]delete[] nums;[/b]
 
Back
Top