Unidirectional linked list

Source: Internet
Author: User

Unidirectional linked list

I have always thought that the linked list is mysterious, and the buckle cable cannot be written. After the logic is passed, I can fully understand the function of adding nodes at the end of the one-way linked list, the one-way linked list can easily write the function for deleting a node at a location and adding a node at any location, and add, delete, modify, and query the node.

Understand the feeling of adding a node function at the end: first, it is clear how the link on the linked list is implemented, second, I thought about the nuances. (for example, when I write other functions, I can't help but think about it, how do I know if the user has a function that calls the node first and deletes the function of the node)

Tip: you can write a one-way linked list function, which is used the same as an array. Learn to use visio to draw a flowchart and try to copy and paste the pseudocode. Then you can implement the function after changing If to a small problem like if.

Logic of one-way linked list: Like a chain, a ring is connected together. Like a chain, each ring is called a node, and each node contains a rectangle.

Linked lists and arrays share the same thing: they both store a pile of continuous data and require continuous storage locations.

Differences between linked lists and arrays: 1. array development is to find a space in the memory to open up the array size, If I char a [3] array, a [0] address is 0x9000, the address of a [1] Must be 0x9001 ......

The linked list is the pointer segment in the previous node to store the address of the next node. In this way, the address of the first node is 0x9000, the second node has a very small probability of 0x9001 (randomly allocated). Because the address of the second node is saved on the first node, does it also constitute "continuous"

2. the array looks for one of the data. If you look for the data of a [2, I can find a [0 + 2], a [1 + 1], a [3-1], or a [2], which is highly efficient in searching, however, if a [2] is deleted, a [3] data must be sent to a [2], a [4] data, a [3], and so on, a new space is added between a [2] and a [1]. Data of a [2] is sent to a [3]... Adding data or creating data in a place that is not at the end will be very troublesome.

Instead, the linked list adds a new node at the second node location, giving the address of the original second node to the new node, and giving the Node Address to the first node, find the address of the third node and give the address directly to the first node. It is very efficient to add and delete data at any location, but in terms of searching, the linked list only knows the address of the first node, and the address of the second node is in the first node. If so, I want to know the data of the fifth node, I have to find the second node from the first node, and find the third node through the second node ...... Very slow

This is the difference between arrays and linked lists.

The following describes the implementation: <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + Environment/b7dsr + Environment/t9Y8L3A + Environment/KtcD9u6/Environment + 47G4wcujrL/J0tS/qsq8tq + 0 + Environment/Environment/ b7dts6hota41eu2zqGixKO + 39XivLi49rTKtrzKx87S19S8us/Shanghai + Shanghai/Shanghai + pgltzybzcm9 "http://www.2cto.com/uploadfile/Collfiles/20140913/20140913085103267.png" alt = "\">





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.