I know how to implement linked list using array. For example we define a struct as follow:
struct Node{
int data;
int link;
}
"data" stores the info and "link" stores the index in the array of next node.
Can anybody tell me what is the advantage and disadvantage of implementing a linked list using array compared to "ordinary" linked list? Any suggestion will be appreciated.
The advantages of linked lists include: Overflow can never occur unless the memory is actually full. Insertions and deletions are easier than for contiguous (array) lists. With large records, moving pointers is easier and faster than moving the items themselves.
Arrays are much more memory-efficient than linked lists. They are also slightly faster at modification, except when they need to be resized.
If you back a linked list with an array, you'll end up with the disadvantages of both. Consequently, this is probably not a very good way to implement it.
Some immediate disadvantages:
I suppose some advantages are:
mmap()
call easily. Though, you'd be better off using some sort of protocol buffer for portability.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With