CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2007
    Posts
    1

    Not Homwork Fun Project

    Im tring an experiment that will generate 7000 integer random numbers and save them in an array. Then I need to copy these 7000 values into a second array, so that I have two identical integer arrays.
    In a function, I want to sort the first array with an un-optimized bubble sort.
    In a second function, I want to sort the second array with an optimized bubble sort.

    So in the main, I would like to print out the time each sort routine took to execute and print out a message determining which sort routine was faster.

    Any Ideas, I made this one up for fun to also learn how to do arrays and counts.


    Any help would be appreciated.....



    I can add some of what I have done if necessary. Thanks to those who help

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Not Homwork Fun Project

    What language do you want to use?
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    Re: Not Homwork Fun Project

    Quote Originally Posted by joebenjamin
    In a second function, I want to sort the second array with an optimized bubble sort.
    (My emphasis)
    That's an oxymoron.

    For precise time computations, with the C programming language, you can compute the difference of two calls to clock() to get the time interval.

    http://www.cppreference.com/stddate/clock.html

    On Win32 systems, you may use GetTickCount() or timeGetTime() in any language that gives access to system functions.

    Be sure that your computations lasts at least a few seconds to get accurate results.
    If it doesn't, iterate the sort operation thousands or millions of times so that it lasts enough time.

    You may also use a profiler for more detailed profiling.
    "inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
    Club of lovers of the C++ typecasts cute syntax: Only recorded member.

    Out of memory happens! Handle it properly!
    Say no to g_new()!

  4. #4
    Join Date
    Sep 2007
    Posts
    1

    Re: Not Homwork Fun Project

    I am using \c programming just basic language. I am totally lost and trying to do this for a project for my math class.

    Joe benjamin.....and this is alos for fun )

  5. #5
    Join Date
    May 2002
    Posts
    10,943

    Re: Not Homwork Fun Project

    Quote Originally Posted by joebenjamin
    I am totally lost and trying to do this for a project for my math class.
    So don't say in the thread title that this isn't for homework.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  6. #6
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    Re: Not Homwork Fun Project

    Questions about the C programming language should be asked on the C++ (non visual C++ issues) forum.
    http://www.codeguru.com/forum/forumdisplay.php?f=9

    The clock() function is declared in time.h.
    http://www.cppreference.com/stddate/clock.html
    "inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
    Club of lovers of the C++ typecasts cute syntax: Only recorded member.

    Out of memory happens! Handle it properly!
    Say no to g_new()!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured