Work on SingleList class big 3
This commit is contained in:
parent
fb0251c2b6
commit
5684c0b29c
|
@ -23,8 +23,10 @@ int main()
|
||||||
bool exit = false;
|
bool exit = false;
|
||||||
int choice = -1;
|
int choice = -1;
|
||||||
int val, key;
|
int val, key;
|
||||||
|
SingleList test2;
|
||||||
while (!exit)
|
while (!exit)
|
||||||
{
|
{
|
||||||
|
test2 = testList;
|
||||||
std::cout << "##### Singly Linked List Menu #####\n\t0. Exit"
|
std::cout << "##### Singly Linked List Menu #####\n\t0. Exit"
|
||||||
<< "\n\t1. Insert\n\t2. Insert at\n\t3. Empty list\n\t4. Peek top of list"
|
<< "\n\t1. Insert\n\t2. Insert at\n\t3. Empty list\n\t4. Peek top of list"
|
||||||
<< "\n\t5. Print list\n\t6. Find\n\t7. Remove\n\t8. Replace\n";
|
<< "\n\t5. Print list\n\t6. Find\n\t7. Remove\n\t8. Replace\n";
|
||||||
|
@ -67,7 +69,7 @@ int main()
|
||||||
|
|
||||||
case PRINT:
|
case PRINT:
|
||||||
testList.print();
|
testList.print();
|
||||||
// test2.print();
|
test2.print();
|
||||||
// test3.print();
|
// test3.print();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,8 @@
|
||||||
*
|
*
|
||||||
* @param rhs SingleList object
|
* @param rhs SingleList object
|
||||||
*/
|
*/
|
||||||
SingleList::SingleList(const SingleList& rhs)
|
SingleList::SingleList(const SingleList& rhs) : head (rhs.head)
|
||||||
{
|
{
|
||||||
head = rhs.head;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,10 +29,11 @@ SingleList::SingleList(const SingleList& rhs)
|
||||||
* @param rhs SingleList object
|
* @param rhs SingleList object
|
||||||
* @return SingleList& The copied rhs SingleList to the lhs of the assignment
|
* @return SingleList& The copied rhs SingleList to the lhs of the assignment
|
||||||
*/
|
*/
|
||||||
SingleList& SingleList::operator=(const SingleList& rhs)
|
SingleList SingleList::operator=(SingleList rhs)
|
||||||
{
|
{
|
||||||
makeEmpty();
|
if (this == &rhs) return *this;
|
||||||
head = rhs.head;
|
std::swap(head, rhs.head);
|
||||||
|
// head = rhs.head;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,9 +117,8 @@ bool SingleList::replace(int val, int key)
|
||||||
*/
|
*/
|
||||||
void SingleList::makeEmpty()
|
void SingleList::makeEmpty()
|
||||||
{
|
{
|
||||||
Node *temp;
|
Node *temp(head);
|
||||||
while(!isEmpty()) {
|
while(!isEmpty()) {
|
||||||
temp = head;
|
|
||||||
head = head->next;
|
head = head->next;
|
||||||
delete temp;
|
delete temp;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ class SingleList{
|
||||||
public:
|
public:
|
||||||
SingleList() : head(NULL) {};
|
SingleList() : head(NULL) {};
|
||||||
SingleList(const SingleList& rhs);
|
SingleList(const SingleList& rhs);
|
||||||
SingleList& operator=(const 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);
|
||||||
|
|
Loading…
Reference in New Issue