為什麼Array這麼好用還需要Linked list 呢?
Question:(from studypool.com-program)
The functions of a linked list can be performed with an array or vector (insert, delete, search, etc.). Why would we go through the complexity of building a linked lists?
ANSWER:
Because linked list is better than array in some case. The instance below will explain it. If we have already had two arrays ,one stored letter"ACD", and the other one is number "123". But you want to add letter "B" into the former array.
In array, first, you have to remove the second array to other space to store. Secondly, remove letter "CD" back for one space to insert letter "B". Then ,put it in.
In this case, maybe you will not feel slow, but if you try to image that there are 10,000 data here ,besides you have to insert a lot of data randomly to the original array. How tired it is!
However, linked list is better than array. In the same case. You just need to change the pointer of letter "A" to indicate letter "B". At last, connect the pointer of letter "B" to letter "C".