Reputation: 19
I don't understand how to take 2 LinkedLists, and add the objects inside to eachother. i.e, Add nodes of LinkedList2, to LinkedList1.
My current code is what I've tried, but I dont know how to access mutliple objects, because cygwin tells me I can only have one argument.
int main()
{
LinkedList firstList, secondList;
firstList += secondList;
}
void LinkedList::operator +=(LinkedList lst)
{
Node* temp = lst.get_head();
while (temp != NULL)
{
Node::value_type student = temp->get_data();
"WHAT DO I ADD HERE".addToTail(student);
temp = temp->get_next();
}
delete temp;
}
Lets say in the "WHAT DO I ADD HERE", because Cygwin says I can only pass in one object, I'd like to be able to add the objects in the second list, to the first list. But I don't understand whats being passed, whether its list 1 or 2, and then how to add to the other.
Upvotes: 1
Views: 75
Reputation: 11
When looking at what your question is asking you should also understand that when adding "LHS += RHS" you are taking the left and adding the right. This means you are passing in the RHS (right hand side) in your case it seems to be secondList. If you use "This->addToTail" should be fine. Also you will not need Delete as it's just a local variable and is not taking memory from the Stack.
Upvotes: 1