median

This is a discussion on median within the C++ Programming forums, part of the General Programming Boards category; Hello, I am trying to write a template for finding the middle of 3 values, and I am going to ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    2

    median

    Hello,
    I am trying to write a template for finding the middle of 3 values, and I am going to call it the "median". For example, the median of {1, 0, 2} is 1. The median of {"abc", "ghi", "def"} is "def". Any help would be great.
    Thanks Frank

  2. #2
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    if you are only having 3 inputs then all you need are a couple of comparisons to see which one is greater than one but not greater than another...
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2
    Right, I understand if it is just integers. But what if it is like the alphabet example. abc def ghi, where def is the middle one?
    Thanks

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    if they are stl strings then you can compare them the same way but old c-style strings you will need to use strcmp()
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    Unregistered
    Guest
    place the strings in an array.
    sort the strings into alphabetical order
    determine which index of the array is the median index
    the string stored in the median index of the array is the median string.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Median filter help
    By JTEK24 in forum Tech Board
    Replies: 10
    Last Post: 07-16-2009, 07:05 PM
  2. Median
    By Neo1 in forum C++ Programming
    Replies: 4
    Last Post: 07-02-2007, 05:00 PM
  3. moving median function
    By supermeew in forum C Programming
    Replies: 0
    Last Post: 05-04-2006, 03:37 PM
  4. computing median value
    By ademkiv in forum C Programming
    Replies: 3
    Last Post: 04-03-2006, 10:43 PM
  5. Computing Mean, Median and Mode Using Arrays
    By Rodneo in forum C++ Programming
    Replies: 0
    Last Post: 05-30-2002, 12:40 AM

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