diff --git a/lectures/09_iterators_linked_lists/README.md b/lectures/09_iterators_linked_lists/README.md index 4b293e6..2755f3e 100644 --- a/lectures/09_iterators_linked_lists/README.md +++ b/lectures/09_iterators_linked_lists/README.md @@ -185,8 +185,10 @@ int main() { // Print the original list std::cout << "Original list:" << std::endl; - for (const auto& person : people) { - std::cout << person.name << " (" << person.age << ")" << std::endl; + std::list::iterator itr = people.begin(); + while(itr != people.end()){ + std::cout << (*itr).name << " (" << (*itr).age << ")" << std::endl; + ++itr; } // Sort the list of Person objects using the custom comparison function @@ -194,8 +196,10 @@ int main() { // Print the sorted list std::cout << "\nSorted list:" << std::endl; - for (const auto& person : people) { - std::cout << person.name << " (" << person.age << ")" << std::endl; + itr = people.begin(); + while(itr != people.end()){ + std::cout << (*itr).name << " (" << (*itr).age << ")" << std::endl; + ++itr; } return 0; diff --git a/lectures/09_iterators_linked_lists/list_sort_objects.cpp b/lectures/09_iterators_linked_lists/list_sort_objects.cpp index 77ba4f3..23739ee 100644 --- a/lectures/09_iterators_linked_lists/list_sort_objects.cpp +++ b/lectures/09_iterators_linked_lists/list_sort_objects.cpp @@ -27,8 +27,10 @@ int main() { // Print the original list std::cout << "Original list:" << std::endl; - for (const auto& person : people) { - std::cout << person.name << " (" << person.age << ")" << std::endl; + std::list::iterator itr = people.begin(); + while(itr != people.end()){ + std::cout << (*itr).name << " (" << (*itr).age << ")" << std::endl; + ++itr; } // Sort the list of Person objects using the custom comparison function @@ -36,10 +38,11 @@ int main() { // Print the sorted list std::cout << "\nSorted list:" << std::endl; - for (const auto& person : people) { - std::cout << person.name << " (" << person.age << ")" << std::endl; + itr = people.begin(); + while(itr != people.end()){ + std::cout << (*itr).name << " (" << (*itr).age << ")" << std::endl; + ++itr; } return 0; } -