C++ Search and Sorting 10

profilekyls61491

  1. Complete Programming Exercise #15 on page 1345.
    1. Fill the array using random numbers.

 srand(time(0));

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

        list[i] = rand() % 20000;

    1. Now copy this array two times.  You need the same exact array, with the same values so you can compare sorts.

·          

·          

·          

    1. Execute each sort on each list(array). Example of function calls,

·                     bubbleSort2(list1, 5000, compBubbleSort, assignBubbleSort); 

·                     selectionSort2(list2, 5000, compSelectionSort, assignSelectionSort); 

·                     insertionSort2(list3, 5000, compInsertionSort, assignInsertionSort);

·          

    1. Use this output code.  You can use different variables.

·             cout << "Number of comparisons---" << endl;

·             cout << "  Bubble sort: " << compBubbleSort << endl;

·             cout << "  Selection sort: " << compSelectionSort << endl;

·             cout << "  Insertion sort: " << compInsertionSort << endl << endl;

·          

·             cout << "Number of item assignments---" << endl;

·             cout << "  Bubble sort: " << assignBubbleSort << endl;

·             cout << "  Selection sort: " << assignSelectionSort << endl;

·             cout << "  Insertion sort: " << assignInsertionSort << endl << endl;

    • 11 years ago
    • 5
    Answer(0)
    Bids(0)