Merge branch 'master' of https://github.com/shaunrd0/klips
This commit is contained in:
commit
424f9b237c
|
@ -23,8 +23,10 @@ int main()
|
|||
bool exit = false;
|
||||
int choice = -1;
|
||||
int val, key;
|
||||
SingleList test2;
|
||||
while (!exit)
|
||||
{
|
||||
test2 = testList;
|
||||
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\t5. Print list\n\t6. Find\n\t7. Remove\n\t8. Replace\n";
|
||||
|
@ -67,7 +69,7 @@ int main()
|
|||
|
||||
case PRINT:
|
||||
testList.print();
|
||||
// test2.print();
|
||||
test2.print();
|
||||
// test3.print();
|
||||
break;
|
||||
|
||||
|
|
|
@ -19,9 +19,8 @@
|
|||
*
|
||||
* @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
|
||||
* @return SingleList& The copied rhs SingleList to the lhs of the assignment
|
||||
*/
|
||||
SingleList& SingleList::operator=(const SingleList& rhs)
|
||||
SingleList SingleList::operator=(SingleList rhs)
|
||||
{
|
||||
makeEmpty();
|
||||
head = rhs.head;
|
||||
if (this == &rhs) return *this;
|
||||
std::swap(head, rhs.head);
|
||||
// head = rhs.head;
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -117,9 +117,8 @@ bool SingleList::replace(int val, int key)
|
|||
*/
|
||||
void SingleList::makeEmpty()
|
||||
{
|
||||
Node *temp;
|
||||
Node *temp(head);
|
||||
while(!isEmpty()) {
|
||||
temp = head;
|
||||
head = head->next;
|
||||
delete temp;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ class SingleList{
|
|||
public:
|
||||
SingleList() : head(NULL) {};
|
||||
SingleList(const SingleList& rhs);
|
||||
SingleList& operator=(const SingleList& rhs);
|
||||
SingleList operator=(SingleList rhs);
|
||||
~SingleList();
|
||||
bool insert(int val);
|
||||
bool insert(int val, int key);
|
||||
|
|
Loading…
Reference in New Issue