Skip to main content
gamedev.net
๐Ÿ”’ Locked

array handling

Started by CProgrammer Jan 15, 2004 at 12:34 AM 2 replies 650+ views
Original Post
CProgrammer
CProgrammer
Whats the fastest way to check if a number already exists in an array?
Fruny
Fruny
If the array is sorted:
T array[size];
bool found = std::binary_search( array, array+size, value );

If not:
T array[size];
bool found = std::find(array, array+size, value) != array+size;



โ€œDebugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.โ€ โ€” Brian W. Kernighan (C programming language co-inventor)

[edited by - Fruny on January 15, 2004 2:37:29 AM]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." โ€” Brian W. Kernighan
CProgrammer
CProgrammer
Thanks std::find will do the Trick

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.