From 8bcb951cee4724fc06a7ddb221e3a000ca544be7 Mon Sep 17 00:00:00 2001 From: Jidong Xiao Date: Mon, 9 Oct 2023 10:57:15 -0400 Subject: [PATCH] adding lab 7 --- labs/07_list_implementation/README.md | 26 ++++++++ labs/07_list_implementation/checkpoint1.cpp | 73 +++++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 labs/07_list_implementation/README.md create mode 100644 labs/07_list_implementation/checkpoint1.cpp diff --git a/labs/07_list_implementation/README.md b/labs/07_list_implementation/README.md new file mode 100644 index 0000000..b0211b8 --- /dev/null +++ b/labs/07_list_implementation/README.md @@ -0,0 +1,26 @@ +# Lab 7 — List Implementation + +## Checkpoint 1 +*estimate: 20-30 minutes* + +The implementation of the dslist class is incomplete. In particular, the class is missing the destroy_list +private member function that is used by the destructor and the clear member function. The provided test +case in [checkpoint1.cpp](checkpoint1.cpp) works “fine”, so what’s the problem? + +Before we fix the problem, let’s use Dr. Memory and/or Valgrind to look at the details more carefully. +You should use the memory debugging tools both on your local machine and by submitting the files to +the homework server. Study the memory debugger output carefully. The output should match your +understanding of the problems caused by the missing destroy_list implementation. Ask a TA if you +have any questions. + +Now write and debug the destroy_list function and then re-run the memory debugger (both locally and on +the submission server) to show that the memory problems have been fixed. Also finish the implementation +of the push_front, pop_front, and pop_back functions. + +**To complete this checkpoint**, show a TA the implementation and memory debugger output before and +after writing destroy_list. + +## Checkpoint 3: +*estimate: TBD* + +Merge Sort an Array. diff --git a/labs/07_list_implementation/checkpoint1.cpp b/labs/07_list_implementation/checkpoint1.cpp new file mode 100644 index 0000000..7ca532b --- /dev/null +++ b/labs/07_list_implementation/checkpoint1.cpp @@ -0,0 +1,73 @@ +#include +#include +#include + +#include "dslist.h" + +int main() { + + // ======================================= + // CHECKPOINT 2 + + // create a list of the sqrt of the first 10 integers + dslist a; + for (int i = 0; i < 10; ++i) + a.push_back(sqrt(i)); + + + // print out details of the list + assert (a.size() == 10); + assert (a.front() == 0); + assert (a.back() == 3); + dslist::iterator itr; + std::cout << "Elements = "; + for (itr = a.begin(); itr != a.end(); ++itr) + std::cout << " " << *itr; + std::cout << std::endl; + + // clear out the list + a.clear(); + + /* + assert (a.size() == 0); + */ + + + /* + // simple tests of push_front, pop_front, and pop_back + a.push_front(5); + a.push_back(7); + a.push_front(3); + a.push_back(9); + assert (a.size() == 4); + + assert (*(a.begin()) == 3); + assert (*(++a.begin()) == 5); + assert (*(++(++a.begin())) == 7); + assert (*(++(++(++a.begin()))) == 9); + + std::cout << "Elements = "; + for (itr = a.begin(); itr != a.end(); ++itr) + std::cout << " " << *itr; + std::cout << std::endl; + + a.pop_back(); + a.pop_front(); + assert (a.size() == 2); + assert (*(a.begin()) == 5); + assert (*(++a.begin()) == 7); + + std::cout << "Elements = "; + for (itr = a.begin(); itr != a.end(); ++itr) + std::cout << " " << *itr; + std::cout << std::endl; + + a.pop_back(); + a.pop_front(); + assert (a.size() == 0); + assert (a.begin() == a.end()); + */ + + return 0; +} +