From 4bc813264710113db4f622ce301880a3bd41d76a Mon Sep 17 00:00:00 2001 From: Alexander Danilchenko <39950413+OlexanderD@users.noreply.github.com> Date: Wed, 30 Oct 2019 23:32:05 +0200 Subject: [PATCH] Update 01_breadth-first_search.cpp (#124) Improved code stylistic integrity. --- .../c++11/01_breadth-first_search.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) 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 +}