How would one search a C++ linked list with a recursive function?
Name:
Anonymous2007-03-29 22:30 ID:wz08uY4M
#include <list>
int searchList(std::list<int> inList, int searchThing) {
int result;
std::list<int>::iterator iter = inList.begin();
if (iter == inList.end()) {
result = 9001;
} else if ((*iter) == searchThing) {
result = (*iter);
} else {
++iter;
result = searchList(std::list<int>(iter, inList.end()), searchThing);
}
return result;
}