Array collections and linked list collections

Source: Internet
Author: User
Tags array length

Statement: The material used in this column is written by the VIP students of the Kay Academy, who has the right to be anonymous and has the final right to interpret the article; The Edith Academy is designed to promote students to learn from each other on the basis of public notes.

Array collection:

Advantages:

1. Order 2. You can perform subscript operation 3. Add Speed Disadvantage: 1. Delete, delete the first, delete the last one, choose a location to remove these are not easy to operate 2. It's inconvenient to insert data.

Example: If you want to insert 88 of the data into the back of 3, then you get 4567 to move back position, so this way is very troublesome, so the use of linked list of the words to facilitate some

Linked List collection:

Introduction: It is like a bicycle chain, its advantage is that you can find a place to add a, you can just find a place to delete one, the chain is divided into two, one is single chain, two is double chain, single chain is you only know home, and do not know the next, double chain is you know home, home also know home, It is to use the address to form the relationship of the chain, single-chain is a single-reference relationship, double-chain is a double-reference relationship

Such as: is a single-chain mode, the note does not know where Xiao Wu, Xiao Wu do not know where the civet, only home know the next home, and the next home do not know the home, if the middle broken a reference, then the data behind the lost

Such as: is a double-chain mode, the family know home, home also know the home, they are reference relations, quoting each other

Its use is just you can complement the shortcomings of the array collection, for example, you want to add a rabbit after the cat, it is easy to add, it has no change, for example, to delete the Civet, the direct Big Black Ox does not point to it, the detour to the rabbit.

Example: Adding a method

The principle of adding a method: First request two attributes, Tou and Wei are null, if you want to save A1 go in, write a if to judge if it is empty under the new an array length of 3, and then save A1 in, so head and tail are pointing to A1, When applying for A2, that refers to the entire array of A1, when the application A3 the first point to A2 the entire array, and the last of the A2 point to the new array, and then the A2 point to the Wei line disconnects, pointing to the new array, so that the formation of a double-chained collection of memory

As a method: To add a method forward, and back to add, back to add directly into the E is OK, because the previous method of writing is to add backwards

Such as: is the method of deleting the previous data

Such as: is the method to delete the following data

Array collections and linked list collections

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.