Libraries for Algorithms [closed]
algorithm* a = new search_algorithm("binary_search");
a->set_data("some text to 开发者_开发知识库be searched");
search_result_t r = a->search("this_text");
Thanks for response.
P.S. Thanks all, but I've "heard" about the STL and Boost. I used a simple example above, but "in my dreams" I want to get this, too:
algorithm* a = new search_algorithm("boyer_moore");
//...
a = new graph_algorithm("brent");
a->set_graph(/*graph_t*/gt);
a->detect_cycles(...);
or even this:
a = new tree_algorithm("kruskal");
tree_t* mt = new tree_t(...);
a->set_tree(mt);
a->get_min_spanning_tree(...);
You've 'heard' of Boost and STL_, so I assume you've heard of
- boyer-moore,
- min spanning tree,
- Brent's algorithm
What is it, exactly, that you are missing?
you can use the 'STL: algorithms' and the boost library. It doesn't always contain what you are looking for but that is because a lot of stuff has to be custom made for your dataset.
The standard library already includes templates for a number of algorithms (including binary search). With the minor proviso that a binary search won't work in the example you've given (it requires sorted input), it's actually even easier than you've shown:
int values[] = { 1, 3, 4, 5, 8, 9};
int *pos = std::lower_bound(values, values+6, 5);
精彩评论