|
General Details
|
|
C++
|
|
Posted 109 Days Ago
|
|
176 Views
|
|
Received 0 Ratings
|
|
Beatiful Code Contest contribution: binary search
Description
Searches an ordered (either ASCending or DESCending) list for the occurence of a value and returns the index at which the value was found (-1 otherwise). My implementation works with all types of values and lists I could think of. See Requirements in "Technical".
Technical
g++ does not take default arguments for templates like I'm using them; I haven't checked other compilers.
Requirements:
-the type of the values inside the list must have the following operators (either by nature, like all numeric datatypes, or by operator overloading): greater than (>), less than (<), equals (==)
-the type of the list itself must have the index ([]) operator (either by nature, like generic arrays or by operator overloading, like std::vector and std::map)
-the type of the list indexes must have the following operators (either by nature, like all numeric datatypes or by operator overloading): plus (+), minus (-), division (/) and less than or equal (<=)
Source Code
Comments
| Please login to post comments. |
More "C++" Source Codes By This Author
Recently Posted "C++" Source Codes
Recently Rated "C++" Source Codes
|