nlist operator + (const
list & l1, const list & l2) {
n //remember, neither l1
nor l2 should be modified!
n list temp(l1); //positions tail at the end of l1
n temp += l2; //how efficient is this?
n return temp;
n}
nOr, should we instead:
nlist operator + (const
list & l1, const list & l2) {
n list temp(l1); //positions tail at the end of l1
n if (!temp.head) temp =
l2;
n else {
n node * dest = temp.tail;
n node * source = l2.head;
n while (source) {
n dest->next = new node;
n dest = dest->next;
n dest->obj = source->obj;
n source = source->next;
n }
n dest->next = NULL; temp.tail = dest;
n temp.ptr = temp.head;
n } return temp;
n}
n
n
n
n
n