diff --git a/06_breadth-first_search/c++11/01_breadth-first_search.cpp b/06_breadth-first_search/c++11/01_breadth-first_search.cpp index 2053590..81cf7d0 100644 --- a/06_breadth-first_search/c++11/01_breadth-first_search.cpp +++ b/06_breadth-first_search/c++11/01_breadth-first_search.cpp @@ -18,9 +18,8 @@ bool search(const T& name, const std::unordered_map>& graph) { std::unordered_set searched; // add all friends to search queue - for (auto friend_name : graph.find(name) -> second) { + for (auto&& friend_name : graph.find(name) -> second) search_queue.push(friend_name); - } while (!search_queue.empty()) { T& person = search_queue.front(); @@ -32,12 +31,10 @@ bool search(const T& name, const std::unordered_map>& graph) { cout << person << " is a mango seller!" << endl; return true; } - std::vector friend_list = graph.find(person) -> second; // add all friends of a person to search queue - for (T friend_name : friend_list) { + for (auto&& friend_name : graph.find(person) -> second) search_queue.push(friend_name); - } // mark this person as searched searched.insert(person); @@ -61,4 +58,4 @@ int main() { std::string name = "you"; bool result = search(name, graph); cout << "Found mango seller: " << result << endl; -} \ No newline at end of file +}