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.


Recommended Answers

All 3 Replies

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.