Sort Function

This is a discussion on Sort Function within the C++ Programming forums, part of the General Programming Boards category; I'm sorry I'm trying to understand what you're saying and trying to get it to work but I'm not understanding. ...

  1. #16
    Registered User
    Join Date
    Aug 2006
    Posts
    127
    I'm sorry I'm trying to understand what you're saying and trying to get it to work but I'm not understanding. Sorry.

  2. #17
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,288
    Alright, with various possibly conflicting things being said people have probably confused you, and you're over thinking things. This is about what you need I believe:
    Code:
    template <class iterator>
       int sortPercentage(iterator start, iterator finish)
    {
        int outOfOrder = 0;
        int numPairs = ...; // Simple subtraction equation here
        for (...)
        {
            if (... > ...)
            {
                outOfOrder++;
            }
        }
        return 100 * outOfOrder / numPairs;
    }
    Other than the ... bits, I've left one other little math problem with it for you to correct. See what values you get from that for an already sorted and a reverse sorted array.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 05-13-2011, 08:28 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Compile problem: sort() cannot be used as a function!?
    By ac251404 in forum C++ Programming
    Replies: 2
    Last Post: 06-01-2006, 12:58 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Replies: 10
    Last Post: 09-15-2004, 01:00 PM

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