C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-28-2001, 12:41 PM   #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
frank is offline   Reply With Quote
Old 10-28-2001, 01:04 PM   #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
Stoned_Coder is offline   Reply With Quote
Old 10-28-2001, 01:17 PM   #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   Reply With Quote
Old 10-28-2001, 01:38 PM   #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
Stoned_Coder is offline   Reply With Quote
Old 10-28-2001, 04:32 PM   #5
Unregistered
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.
  Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 06:30 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

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