Rename directories, fix assignment operator in singlelist

This commit is contained in:
Shaun Reed 2020-04-26 21:47:59 -04:00
parent 255ba5a291
commit 110ac83be8
4 changed files with 6 additions and 5 deletions

View File

@ -19,7 +19,7 @@ int main()
{ {
std::cout << "Driver: \n"; std::cout << "Driver: \n";
SingleList testList; SingleList testList, test;
bool exit = false; bool exit = false;
int choice = -1; int choice = -1;
int val, key; int val, key;
@ -41,6 +41,7 @@ int main()
std::cin >> val; std::cin >> val;
std::cin.clear(); std::cin.clear();
testList.insert(val); testList.insert(val);
test = testList;
break; break;
case INSERTAT: case INSERTAT:
@ -67,6 +68,7 @@ int main()
case PRINT: case PRINT:
testList.print(); testList.print();
test.print();
break; break;
case FIND: case FIND:

View File

@ -42,11 +42,10 @@ SingleList::SingleList(const SingleList& rhs)
* @param rhs SingleList object * @param rhs SingleList object
* @return SingleList& A shallow copy of the rhs SingleList in the assignment * @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; if (this == &rhs) return *this;
else head = rhs.head; std::swap(head, rhs.head);
return *this; return *this;
} }

View File

@ -22,7 +22,7 @@ class SingleList{
public: public:
SingleList() : head(NULL) {}; SingleList() : head(NULL) {};
SingleList(const SingleList& rhs); SingleList(const SingleList& rhs);
SingleList operator=(SingleList& rhs); SingleList operator=(SingleList rhs);
~SingleList(); ~SingleList();
bool insert(int val); bool insert(int val);
bool insert(int val, int key); bool insert(int val, int key);