Arrary
The address of arrary in memory is next to each other, as shown in the figure below
As shown in the figure above, the first row can only store 3 data. When storing the fourth data, because the grid in the first row and the fourth column is already occupied, it is necessary to find the address for storage again. There can be a compensation measure: that is to allocate 10 locations at a time, so that they can be connected, but it will waste storage space. So the disadvantage of Arrary is that it is extremely slow when inserting new data (need to find the location for storage).
linked list
Data can be stored anywhere
In fact, in each grid, not only data is stored, but also the address of the next data is stored, as shown in the figure below
The advantages and disadvantages of linked list and arrary
Because each position in the linked list stores the address of the next content, it is necessary to traverse the entire list . For example, if there is a linked list with 5 contents, you need to take out the contents on address 5, then you need to read the first unit first Content, and get the address of the second content, then read the second content, get the address of the third content, until the fifth position.
Because the addresses of arrary store data are sequential, the content can be taken out at will.
arrary and linked list read and write complexity
The complexity of reading, inserting, and deleting arrary and linked lists
Random read, can read the information on the data at any position, this is the characteristic of arrary
Sequential reading, you can only read one after another when reading, which is the characteristic of list.
Highlights of this chapter