Sort this...

This is a discussion on Sort this... within the A Brief History of Cprogramming.com forums, part of the Community Boards category; You have 4 variables (A, B, C, D). And you have to sort them for largest to smallest. What is ...

  1. #1
    free(me);
    Join Date
    Oct 2001
    Location
    Santo Domingo, DN, Dominican Republic
    Posts
    98

    Sort this...

    You have 4 variables (A, B, C, D). And you have to sort them for largest to smallest. What is the best way to do this, that is the way which makes the least comparisons.

    I don't know anything about algorithms (sorting), so all the info on that didn't really help me.

    I think the best way would be this:

    Step 1: Compare A to B
    Step 2: Compare B to C
    Step 3: Compare the two biggest
    Step 4: Compare the two smallest.

    Am i right?

    adios,
    biterman.
    Do you know how contemptous they are of you?

  2. #2
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    One of numerous sort algorithm sites with cute animations...

    http://www.geocities.com/SiliconVall...854/Sort1.html

    ... although if you only have 4 variables, it hardly seems worth it!
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    61
    that was a very cool applet.

  4. #4
    free(me);
    Join Date
    Oct 2001
    Location
    Santo Domingo, DN, Dominican Republic
    Posts
    98

    True...

    But the ignorant have to start learning somewhere... myself being the ignorant.

    Can you point me to some literature on the subject that might lessen my ignorance? Or is all this just a question of knowledge in mathematics and how to implement it in programming languages?

    By the way, what would be the most efficient (fastest) way to sort those (admittedly few) variables? In essence, was i right? If not, what is the right answer?

    Thank you,
    biterman.
    Do you know how contemptous they are of you?

  5. #5
    It's full of stars adrianxw's Avatar
    Join Date
    Aug 2001
    Posts
    4,831
    As to are you right, I don't know, you say compare, but what are you doing with them after you compare them? You should really try to think this out for yourself, it is a good exercise in problem solving/logical thinking.

    If you can't, the link I gave you had a link to get the sort source, it is in java, but should be easy enough for a C programmer to follow. An alternative link with C code is...

    http://www.programmersheaven.com/zone3/cat475/
    Wave upon wave of demented avengers march cheerfully out of obscurity unto the dream.

  6. #6
    free(me);
    Join Date
    Oct 2001
    Location
    Santo Domingo, DN, Dominican Republic
    Posts
    98

    Oh...

    but think about it for myself is what i have done for several days, not to say a week or more. Of course, i arrived at the conclusion i shared with you after only a few minutes of pondering upon it. But being unsure of whether i was right or not, and not knowing how to prove one way or the other, i decided to keep pondering on it, and so i did. Then i thought it would be interesting to know what all of you might think, and maybe you would be able to tell me if i was right or not.

    It is a good problem indeed.

    thank you,
    dario.
    Last edited by biterman; 10-18-2001 at 05:42 AM.
    Do you know how contemptous they are of you?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Straight Insertion Sort function problem
    By StaticKyle in forum C++ Programming
    Replies: 6
    Last Post: 05-12-2008, 04:03 AM
  2. threaded merge sort
    By AusTex in forum Linux Programming
    Replies: 4
    Last Post: 05-04-2005, 04:03 AM
  3. Sorting
    By vasanth in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 11-10-2003, 04:21 PM
  4. radix sort and radix exchange sort.
    By whatman in forum C Programming
    Replies: 1
    Last Post: 07-31-2003, 12:24 PM
  5. Shell Sort vs Heap Sort vs Quick Sort
    By mackol in forum C Programming
    Replies: 6
    Last Post: 11-22-2002, 07:05 PM

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