View Single Post
Old 05-01-2005, 08:07 AM   #2 (permalink)
Rekna
Junkie
 
I'm confused by your question. You are trying to find a number in an unordered list right? Just do a simple linear search to find it. It sounds like you are working with floating point numbers though which means rounding errors will ruin your equality. So then use an epislon factor to determine equality.

For instance here is some psuedo code


Code:
int Search(List L, double number)
{
   e=10^-6
   for i=1 to L.length
        if (abs(L[i]-number)<e)
             return i
   return -1
}
where -1 indicates the number is not in the list.

Last edited by Rekna; 05-01-2005 at 08:09 AM..
Rekna is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76