find the minus Key

  • Thread starter Thread starter Const
  • Start date Start date
C

Const

Hi,

This is what i would like to do :
I have an Hashtable where all of my Keys are intergers.

The user choose a number, and i want to find the Closest minimal values
of my Keys.

For example :

mys Keys are : 0, 100, 250, 500.

The user enter the value 200, the programme should return 100.
The user enter the value 10, the programme should return 100.
The user enter the value 499, the programme should return 250.

Excuse my english, i hope i could be understand... :)

Thx!

Const.
 
The user enter the value 200, the programme should return 100.
The user enter the value 10, the programme should return 100.
The user enter the value 499, the programme should return 250.

Unfortunately there is no built-in way to do this... but if you use a
SortedList instead of a Hashtable, then you can iterate through each of the
keys, and once you find a value greater than what you are looking for just
return the previous one.

-mdb
 
Const said:
This is what i would like to do :
I have an Hashtable where all of my Keys are intergers.

The user choose a number, and i want to find the Closest minimal values
of my Keys.

For example :

mys Keys are : 0, 100, 250, 500.

The user enter the value 200, the programme should return 100.
The user enter the value 10, the programme should return 100.
The user enter the value 499, the programme should return 250.

Excuse my english, i hope i could be understand... :)

Well, you could use a SortedList instead of a Hashtable, and then do a
binary chop to find the nearest value. Otherwise you'll have to go
through all the keys in turn.
 
Michael Bray a écrit :
newsreader-07.noos.net:




Unfortunately there is no built-in way to do this... but if you use a
SortedList instead of a Hashtable, then you can iterate through each of the
keys, and once you find a value greater than what you are looking for just
return the previous one.

-mdb

I'll try, thanks to you and Jon ! :)
 
Back
Top