I was told to use bubble sort to sort the arrays. what i need to do is read in one array and have to sort into the other array but i haven't been able to figure it out here's the code i have so far. i've been trying to manuplate many different ways and research online, but i haven't been able to figure it out.

void Sort(const double inputArray[], double outputArray[], int inputLengthOfList)
{
    //Local Variables
    int pass;
    int i;
    double hold;

    /* bubble sort */
    /* loop to control number of passes */
    for ( pass = 1; pass < inputLengthOfList; pass++ ) 
    {

        /* loop to control number of comparisons per pass */
        for ( i = 0; i < inputLengthOfList - 1; i++ ) 
        {
            /* compare adjacent elements and swap them if first
            element is greater than second element */
            if ( inputArray[ i ] > inputArray[ i + 1 ] ) 
            {
                hold = inputArray[ i ];
                outputArray[ i ] = inputArray[ i + 1 ];
                outputArray[ i + 1 ] = hold;
            } /* end if */
        } /* end inner for */
    } /* end outer for */
}// end function Sort

Any suggestion or examples would be greatly appreaiated.

Thanks
zingwing

Edited 4 Years Ago by deceptikon: Fixed code block

the easiest way to do it is to just copy everything from InputArray to OutputArray, then sort OutputArray. If you are allowed to use it you can copy the entire array with one line of code using memcpy() function. If you can't use that function then do the copy in a loop.

Edited 4 Years Ago by Ancient Dragon: z

how would i go about using the memcpy function to copying the first array to the second?
something like this?

memcpy(outputArray,inputArray, inputLengthOfList);

Almost right, the last parameter has to be multiplied by sizeof(int) to produce the correct number of bytes. The last parameter to memcpy() is in bytes.

Edited 4 Years Ago by Ancient Dragon: x

This article has been dead for over six months. Start a new discussion instead.