diff --git a/plates/linkedlists/Makefile b/plates/singlelist/Makefile similarity index 100% rename from plates/linkedlists/Makefile rename to plates/singlelist/Makefile diff --git a/plates/linkedlists/driver.cpp b/plates/singlelist/driver.cpp similarity index 97% rename from plates/linkedlists/driver.cpp rename to plates/singlelist/driver.cpp index be746e1..bcc4774 100644 --- a/plates/linkedlists/driver.cpp +++ b/plates/singlelist/driver.cpp @@ -19,7 +19,7 @@ int main() { std::cout << "Driver: \n"; - SingleList testList; + SingleList testList, test; bool exit = false; int choice = -1; int val, key; @@ -41,6 +41,7 @@ int main() std::cin >> val; std::cin.clear(); testList.insert(val); + test = testList; break; case INSERTAT: @@ -67,6 +68,7 @@ int main() case PRINT: testList.print(); + test.print(); break; case FIND: diff --git a/plates/linkedlists/singlelist.cpp b/plates/singlelist/singlelist.cpp similarity index 99% rename from plates/linkedlists/singlelist.cpp rename to plates/singlelist/singlelist.cpp index 6f0224b..90308bb 100644 --- a/plates/linkedlists/singlelist.cpp +++ b/plates/singlelist/singlelist.cpp @@ -42,11 +42,10 @@ SingleList::SingleList(const SingleList& rhs) * @param rhs SingleList object * @return SingleList& A shallow copy of the rhs SingleList in the assignment */ -SingleList SingleList::operator=(SingleList& rhs) +SingleList SingleList::operator=(SingleList rhs) { if (this == &rhs) return *this; - else head = rhs.head; - + std::swap(head, rhs.head); return *this; } diff --git a/plates/linkedlists/singlelist.h b/plates/singlelist/singlelist.h similarity index 97% rename from plates/linkedlists/singlelist.h rename to plates/singlelist/singlelist.h index ca2f394..24bcda2 100644 --- a/plates/linkedlists/singlelist.h +++ b/plates/singlelist/singlelist.h @@ -22,7 +22,7 @@ class SingleList{ public: SingleList() : head(NULL) {}; SingleList(const SingleList& rhs); - SingleList operator=(SingleList& rhs); + SingleList operator=(SingleList rhs); ~SingleList(); bool insert(int val); bool insert(int val, int key);