Thread: mode function creation

  1. #1
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472

    Wink mode function creation

    hola,

    Anbody know a good way of making a function that returns the mode of a series of data values? i.e the most frequently occuring values? I would like to code it rather than find a header file with it in as i need to learn a bit more about string handling routines in c/c++ as i am self taught. i also want to avoid sending the program output to excel and getting round it like that.

    Cheers,

    Paul.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Sort them into order, using say qsort(), then count how many of each identical value there is (they'll all be together after the sort).
    The value with the longest run is the mode.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    thanks hombre, will give it a whirl,

    Would you take a look at my query on a gambling routine i wrote? its not a problem wit code, would just like to see your opinion on it...

    Cheers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  5. Replies: 5
    Last Post: 02-08-2003, 07:42 PM