![]() |
| | #1 |
| Registered User Join Date: Oct 2001
Posts: 2
| median 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 |
| frank is offline | |
| | #2 |
| Skunkmeister 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 |
| Stoned_Coder is offline | |
| | #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 |
| frank is offline | |
| | #4 |
| Skunkmeister 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 |
| Stoned_Coder is offline | |
| | #5 |
| Guest
Posts: n/a
| 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. |
|
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Median filter help | JTEK24 | Tech Board | 10 | 07-16-2009 06:05 PM |
| Median | Neo1 | C++ Programming | 4 | 07-02-2007 04:00 PM |
| moving median function | supermeew | C Programming | 0 | 05-04-2006 02:37 PM |
| computing median value | ademkiv | C Programming | 3 | 04-03-2006 09:43 PM |
| Computing Mean, Median and Mode Using Arrays | Rodneo | C++ Programming | 0 | 05-29-2002 11:40 PM |