+ 2
Why linked list is better than Array?
2 Answers
+ 4
List Advantages
There are many advantages to both arrays and linked lists, but it ultimately depends on how you use them. In a linked list, the data for each item of the list is stored in separate place in memory, which allows for the size of the list to change whenever needed. This also makes it easy to add elements to the ends and even insert them into the middle of the list. For arrays, especially of larger sizes, it is extremely expensive to insert elements into the middle.
Array Advantages
On the other hand, accessing an element for arrays is less expensive to perform than it is for lists. Because arrays are fixed spaces in memory, all that is needed is an index offset and you will directly receive the data at that offset in memory. For lists, you have to traverse all elements before (or after if starting from the end of a doubly linked list) the element you are trying to get to
I hope this helps. Happy Coding :)
+ 2
It depends on conditions. If you need a container and you are gonna insert and remove items frequently, then linked list will do great. But if you need random access performance, then array is better.
I'd recommend to read a book about data structure.