Array Collections and Linked List Collections

Disclaimer: The materials used in this column are written by VIP students of Kaige Academy. Students have the right to remain anonymous and have the right to final interpretation of the article. Kaige Academy aims to promote VIP students to learn from each other based on public notes.

Array collection:

advantage:

1. Orderly 2. Subscript operations can be performed 3. Fast adding speed Disadvantages: 1. Delete, delete the first, delete the last, select a location to delete these are inconvenient to operate 2. It is also inconvenient to insert data

Example: For example, if you want to insert the data of 88 to the back of 3, then you need to move the position back when you get 4567, so this method is very troublesome, so it is more convenient to use the linked list collection

image

A collection of linked lists:

Introduction: It is like the chain of a bicycle. Its advantage is that you can add one in any place, or delete one in any place. The chain is divided into two types, one is single chain, the other is double chain, single chain That is, you only know the upper house, but not the lower house. The double chain means that you know the upper house, and the upper house also knows the lower house. It uses the address to form the chain relationship. A single chain is a single reference relationship, and a double chain is a double chain. reference relationship

image

As shown in the figure below: It is a single-chain mode. The note does not know where Xiao Wu is, and Xiao Wu does not know where the civet cat is. Only the upper family knows the lower family, and the lower family does not know the upper family. If a quote is interrupted in the middle, then the back data is lost

image

As shown in the figure below: It is a double-chain model. The next family knows the upper family, and the upper family knows the next family. They all refer to each other and refer to each other.

image

Its usefulness is that it can just make up for the shortcomings of the array set. For example, if you want to add a Tusky behind the civet, it is easy to add it. just fine

image

Example: The following figure is the method of adding

image

The principle of adding method: first apply for two attributes, tou and wei are both null, if you want to save A1 in, write an if to judge if it is empty, then create an array with a length of 3, and then save A1 in , then both the head and the tail point to A1. When applying for A2, the entire array of A1 is referenced. When applying for A3, the first cell points to the entire array of A2, and the last cell of A2 points to the new array. Then put A2 The line pointing to wei is disconnected and points to a new array, thus forming a double-chained collection memory

image

The method as shown in the figure below: it is to add the method forward, and add it backward. It is enough to add e directly, because the method written before is added backward.

image

As shown below: is the method to delete the previous data

image

As shown below: is the method to delete the following data

image

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325385639&siteId=291194637