Open DaddyTrap opened 8 years ago
@DaddyTrap Just a mistake... you're right.
@ghostbody Well....Thank you all the same!
@ghostbody I don't know why vector is in this question...The question description is too long.I guess I may miss somthing important.But ......
I remember that Fashi have ever said that when it refers to the pointer, it need to use deep copy.But +7 you ask me to use shadow copy..I'm confused.
@KatharinaLin In merge sort, if you use deep copy, for a 8-length linked list, it can create 2+4+8 = 14 copies and it waste many spaces.
Not ALL pointers should be deep copied. It depends. For example in this situation, it is no need to create new things because what we want to change is the list we sort.
In a word, if you don't want to change the data of the list, use deep copy. If you think changing the data is OK, then using shallow copy is OK, too.
Hope you can get some help here....
OK...I think it myself to understand.....thanks a lot
@KatharinaLin The question Collection is from the standard library of JAVA which is a programming language based at polymorphic. The ArrayList in java is similar to Vector in C++. However in Vector in java means thread-safe ArrayList.
So ArrayList in java and Vector in C++ are the same. They are all dynamic array implementation.
For merge sort, here is an example.
There is no need to have so many memory copies while you are doing merge sort in a list. So shadow copy or in other words, pointer operations should be applied instead.
Hope it can help you.
En ... Thank you.Get it!
A classmate asked me this question, but I don't have an answer...
In this week's assignment "(15 C++ Homework) D&A 5 Collection with Inheritance" In LinkedList.hpp:
But in ArrayList.hpp:
In my opinion, I think using
virtual
in inheritance means I want to copy the base class only once when I use multiple inheritance. So, why ArrayList's declaration is different from LinkedList's here? Or, this is only a little mistake?