DEV Community

Fredson Gisa Kaze
Fredson Gisa Kaze

Posted on • Edited on

Difference between Linked List and Array in CPP

difference-between-arrays-and-linked-list

Basically, an array is a set of similar data objects stored in sequential memory locations under a common heading or a variable name.

While a linked list is a data structure that contains a sequence of the elements where each element is linked to its next element. There are two fields in an element of the linked list. One is the Data field, and the other is the link field, Data field contains the actual value to be stored and processed. Furthermore, the link field holds the address of the next data item in the linked list. The address used to access a particular node is known as a pointer.

Another significant difference between an array and a linked list is that Array has a fixed size and required to be declared prior, but Linked List is not restricted to size and expand and contract during execution. Below is a summarized table showing differences clearly

1_Lnb0IARMGORn_c-gYf-24g

Top comments (4)

Collapse
 
jacquestz profile image
Twizeyimana Jacques

Thanks Fredson.

Collapse
 
taikedz profile image
Info Comment hidden by post author - thread only accessible via permalink
Tai Kedzierski • Edited

What you describe above (especially the advantages and disadvantages section) is false within the scope of Python. It is also false in Ruby, JavaScript and Lua, and probably many other languages too.

Data types can be quite language dependent. In Python, there is no such thing as an "array" (well, there is an array library, but it has nothing to do with what you describe here). There is no use of "linked lists."

You dig tag C++ and Java, and yes, this distinction is relevant there - but I recommend a tag edit to remove Python as this can counter-productive for their learning.

I already flagged this up on someone else's post who was saying the same stuff, so you can check the details there.

Collapse
 
gustavy profile image
Manzi Gustave

Thanks

Collapse
 
gisakaze profile image
Fredson Gisa Kaze

great!

Some comments have been hidden by the post's author - find out more