Thread: someone please help

  1. #1
    Unregistered
    Guest

    Unhappy someone please help

    hello i was wondering if someone could help me out, i have to create a program that creates an array of 50000 integers,
    executes an bubblesort rountine in this arrayand time its execution, display the sorted array of every 1000th value, 10 values per line, repopulate the array with the same 50000 random integers by using the same seed, execute a impoved bubblesort on this arrayand time its execution, display this array,
    again repopulate the array with the same 50000 integers, execute the recursive mergesort rountine on this array and time its execution, and lastly display the sorted array. This is what I have so far, any help would be grateful, or even a simple what to do for the next step is





    #include <iostream.h>
    #include <time.h>
    #include <stdlib.h>
    #include <iomanip.h>

    int ARRAY[50000];
    void Obub( int, int );
    void printArray( int[], int );

    int value;

    int main (){
    srand( time( 0 ) );
    for ( int num = 1; num <= 50000; num++ )
    ++value[ 1 + rand() % 1000 ];

    return 0;
    }
    void Obub( int ARRAY[], int size )
    {
    int hold;

    for ( int pass = 1; pass < size; pass++ )

    for ( int j = 0; j < size - 1; j++ )

    if ( ARRAY[j] > a[ j + 1 ] ) {
    hold = ARRAY[j];
    ARRAY[j] = a[j + 1 ];
    ARRAY[ j + 1 ] = hold;
    }
    }

    void printArray( int ARRAY[], int size )
    {
    for ( int j = 0; j < size; j++ ) {

    if ( j % 10 == 0 )
    cout << endl;

    cout << setw( 2 ) << a[ j ];
    }
    }

  2. #2
    Unregistered
    Guest
    Hi there!

    You can use selection sort... it's goot one! :-) it's not the fastest you can find, but it's easy... try and see if it works fine for you...

    Here is a tutorial about the selection sort:
    http://www.cpp-home.com/tutorial.php?113_1

    And here is a working code:
    http://www.cpp-home.com/code.php?82_1

    I hope this helps!

    Ilia Yordanov,
    www.cpp-home.com ; C++ Resources
    tutorials.cpp-home.com ; More than 130 tutorials
    code.cpp-home.com ; More than 60 code
    forums.cpp-home.com ; Get Answered

Popular pages Recent additions subscribe to a feed