This Is Not Homework/ A Project

This is a discussion on This Is Not Homework/ A Project within the C Programming forums, part of the General Programming Boards category; I am trying to write a program that will generate 7000 random integers, then sort them into an optimized bulbblesort ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    1

    Post This Is Not Homework/ A Project

    I am trying to write a program that will generate 7000 random integers, then sort them into an optimized bulbblesort and also a un-optimized sort for fun.I could post what i have started but it is not much at all. The final thing I would like to try is to write a timer or counter that will tell me what the times were for each sort and compare which one was done faster (should be optimized). \even if I could get the oprtimized with a timer going i could definetly figute out the unoptimized. Confusing to me......or you yet?
    I need some help on this one big time. This is not homework but a chapter in a book i am reading that offers no solid explanations or help. Is more of a excersices with no real examples to help learn. THE BOOK SUCKS !!!!

    any ideas, sample codes, or snippets would be useful.

    Thanks to everyone that can help ....

    william_loney

  2. #2
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    i think knowing what you have done and/or where you are stuck is the best place to start. it seems you have three requirements: generating X random integers, creating an 'optimized' (shrinking?) bubble sort function, and an 'un-optimized' sort function.

    generating the random integers im sure you have, so we need to work on the two functions. could you explain what you mean by optimized bubble sort (is it a shrinking bubble sort?). same with your 'unoptimized' sort. once we have the two functions, determining which one is better would be the easier part.

    one way to do it is to determine the number of iterations (or more likely, recursive calls, as i imagine it would be a recursive function). for an iterative function, you could have a print statement inside your loop; for a recursive function you would put it at the beginning of the function. you can then determine how many calls each function took to compare them. if you want to time the functions, you would probably need a very precise timing method.

    hope it helps

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Bubblesort (even the "optimized" kind), is very much UN-optimized, so you won't have much of a comparison, there.

    I strongly suggest you Google "bubblesort graphic" and find one of the several sites that have a graphic representation of how bubblesort works, compared to other sorting methods.

    From fastest to slowest, the normal sorting speeds for unknown range of integers, rank:

    1) Quicksort (a marvel, but easily broken algo). Needs tuning frequently to reach top speed, can be slow with already sorted data. Radial and Mergesort.

    2) Shell sort. Easy to work with and understand. Runs a bit like some slower algo's, but the way it moves each element being sorted further, in one "jump", (using clever offsets), makes it much faster.

    3) Bubble, Selection, etc. Very easy to program, but stupid if you need more than a second or two of computer time to sort your data.

    You may want to pick up a better book. I recommend "Beginning C" by Ivor Horton. Great book, plenty of example problems. Great foundation for every programmer in C.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem Displaying a Struct
    By rockstarpirate in forum C++ Programming
    Replies: 16
    Last Post: 05-05-2008, 09:05 AM
  2. added start menu crashes game
    By avgprogamerjoe in forum Game Programming
    Replies: 6
    Last Post: 08-29-2007, 01:30 PM
  3. Dynamic Binding
    By gpr1me in forum C++ Programming
    Replies: 1
    Last Post: 03-24-2006, 08:01 AM
  4. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21