Hello,i am getting something strange and unfortunetely i dont understand it.
Code:
#include "LinkedList.h"
void concatenate(LinkedList<string>& object1,LinkedList<string>& object2){
if(object1.head==NULL){
object1.head=object2.head;
}
}
int main(){
LinkedList<string> LinkedList1;
LinkedList<string> LinkedList2;
LinkedList2.AddNode("anna");
LinkedList2.AddNode("montanna");
LinkedList2.AddNode("annamontanna");
concatenate(LinkedList1,LinkedList2);
LinkedList1.DisplayList();
keep_window_open();
}
Code:
void DisplayList(){
curr=head;
while (curr!=NULL){
cout<<curr->data;
curr=curr->next;
}
}
How come object1.head=object2.head; copy the the entire object2 list to object1 list by just copying the head of it?