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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:05:35+00:00 2026-06-17T17:05:35+00:00

Output I’m getting: The base array 7290 5184 6174 8003 7427 2245 6522 6669

  • 0

Output I’m getting:

  • The base array
  • 7290 5184 6174 8003 7427 2245 6522 6669 8939 4814 The
  • Sorted array
  • -33686019 2245 4814 5184 6174 6522 6669 7290 7427 8003
  • Press any key to continue . . .

I have no idea where this, -33686019, number is coming from. I’ve posted all of the code because I really don’t know what could be causing it.

The Bubble Sort:

#include "Sorting.h"

double Sorting::bubbleSort( int size )
{
    //Make a copy of our "master key" array for us to sort
    int *toSort = whichArray(size);
    int *theArray = copyArray( toSort, size );  
    double time;

    cout << "The base array" << endl;
    for(int i = 0; i < 10; i++ )
    {
        cout << theArray[i] << endl;
    }

    //The sort

    //Begin time
    timer.startClock();

    bool swapped = true;
    int temp = 0;

    while( swapped == true )
    {
        swapped = false;

        for( int i = 0; i < size; i++ )
        {
            if( theArray[i+1] < theArray[i] )
            {
                /*temp = theArray[i+1];

                theArray[i+1] = theArray[i];
                theArray[i] = temp;*/

                swap(theArray[i + 1], theArray[i]);
                swapped = true;
            }
        }
    }

    time = timer.getTime();

    cout << "The Sorted array" << endl;
    for(int x = 0; x < 10; x++ )
    {
        cout << theArray[x] << endl;
    }

    return time;
}

The Sorting Class:

#ifndef SORTING_H
#define SORTING_H

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
//^For random numbers
#include <iostream>

#include "TimerSystem.h"
#include <iomanip>

using namespace std;

class Sorting
{
private:
    //The below pointers will point to arrays that hold the data sets
    int *n10;
    int *n100;
    int *n1000;
    int *n10000;

    TimerSystem timer;

    double runs[4][4];

    public:
    Sorting();
    ~Sorting(){};

    //Testing functions
    void printArray();
    void print2DArray();
    void dryRun();

    //Data manging and creating
    int randomNumGen();
    int* arrayGen( int size );//Returning a pointer
    int* copyArray( int *toCopy, int size );//Makes an array that the program can sort. The leaves the original array intact
    int* whichArray( int size );
    void datasetRun( int whichSort );//Does three runs of a sort and gets the average for all 4 array sizes

    //Sorts
    double bubbleSort( int size );
};

#endif

Other Called Functions:

#include "Sorting.h"

int Sorting::randomNumGen()
{
    int randomNumber = rand() % 10000 + 1;

    if( randomNumber > 10000 || randomNumber < 0 )
    {
        system("pause");
    }

    return randomNumber;
}

int* Sorting::arrayGen( int size )
{
    int *theArray= new int[size];

    for( int i = 0; i < size; i++ )
    {
        theArray[i] = randomNumGen();
    }

    return theArray;
}

int* Sorting::copyArray( int *toCopy, int size )
{
    int *newArray = new int[size];

    for( int i = 0; i < size; i++ )
    {
        newArray[i] = toCopy[i];
    }

    return newArray;
}

int* Sorting::whichArray( int size )
{
    if( size == 10 )
    {
        return n10;
    }
    else if( size == 100 )
    {
        return n100;
    }
    else if( size == 1000 )
    {
        return n100;
    }
    else if( size == 10000 )
    {
        return n1000;
    }

    return NULL;
}

void Sorting::datasetRun( int whichSort )
{
    //1: Bubble 
    //2: Insertion
    //3: Selection
    //4: Shell 
    //5: Quick
    //6: Merge

    int col = 0;
    int row = 0;
    int set = 10;
    bool runDone = false;

    if( whichSort == 1 )
    {
        for( int row = 0; row < 4; row++ )
        {
            for( int col = 0; col < 4; col++ )
            {
                runs[row][col] = bubbleSort( set );
            }

            //set = set * 10;
        }
    }
}

//Constructor
Sorting::Sorting()
{
    //For the random number generator
    srand( time(NULL) );

    n10 = arrayGen( 10 );
    n100 = arrayGen( 100 );
    n1000 = arrayGen( 1000 );
    n10000 = arrayGen( 10000 );
}

//Functions for testing
void Sorting::printArray()
{
    int size = 10000;

    for( int i = 0; i < size; i++ )
    {
        cout << n10000[i] << " ";
    }
}

void Sorting::print2DArray()
{
    for( int height = 0; height < 4; height++ )
    {
        for( int width = 0; width < 4; width++ )
        {
            cout << runs[height][width] << endl;
        }

        cout << "\n\n";
    }
}

The Main Function:

#include "Sorting.h"

void main()
{
    //Makes the numbers easily readable
    cout.setf(ios::fixed | ios::showpoint);
    cout.precision(16);

    Sorting theSorting;

    //theSorting.printArray();

    //cout << theSorting.bubbleSort( 10 ) << endl;

    //theSorting.datasetRun(1);
    //theSorting.print2DArray();

    theSorting.bubbleSort( 10 );

    system("pause");
}
  • 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-17T17:05:36+00:00Added an answer on June 17, 2026 at 5:05 pm

    The following bit is not correct:

    for( int i = 0; i < size; i++ )
    {
        if( theArray[i+1] < theArray[i] )
    

    It is accessing one beyond the boundary of the array. The for loop should probably be:

    for( int i = 0; i < size - 1; i++ )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The output of eg >>w = whos; returns an array of structs. I would
Output says all array values are anxiety when the words of file fileIn are
the output is like below restored in a output.txt file: array ( 'IMType' =>
My output prints positive or negative repeatedly. Why am I getting an infinite loop?
The output of my JSON call can either be an Array or a Hash.
output.videoSettings = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt:kCVPixelFormatType_32BGRA] forKey:(id)kCVPixelBufferPixelFormatTypeKey]; I get this error on this particular
output of passenger-memory-stats ----- Passenger processes ----- PID VMSize Private Name ------------------------------- 28572 207.4
Output in Log: ibtoold(1642,0x7fff78b64960) malloc: error for object 0x7fbf38056a08: incorrect checksum for freed object
The output of datetime.datetime.now() outputs in my native timezone of UTC-8. I'd like to
wget --output-document=/var/www/projects/meme/upload/1341233172.jpeg http://memecaptain.com/i?u=http://cdn.memegenerator.net/images/400x/528461.jpg&t1=dm&t2=cmks I used following command to download a meme but wget is

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.