Use an adjacent linked list to store Graphs

Source: Internet
Author: User

Previously, I used the adjacent matrix to store graph information. However, I found that the space provided by some questions was not enough to open a two-dimensional array, so I could no longer use the adjacent matrix for storage, then I learned how to use the link list.

The adjacent linked list first has a struct used to store the information of the entire graph. This struct contains some basic information about the graph, such as the number of vertices and the number of edges, there is also an array that stores all vertex information. Of course, this array is the structure array that will be mentioned later to store vertex information. Its Array range is the range of vertex numbers in the graph.

There is also a struct that stores vertex information. This struct contains basic vertex information, such as vertex numbers. There are also two linked list headers pointing to edge nodes that will be mentioned next, the two linked lists are the output edge linked list and the inbound edge linked list respectively.

As for the edge linked list node structure, it is used to create an edge linked list and an inbound edge linked list. The same structure is used to create a linked list, which is divided into two parts. One is a data block, it is used to store the basic information of a node, and the other is a pointer to the next edge node.

Here we will describe the output-edge linked list and the inbound-edge linked list.
If the output edge linked list of node a is used, it indicates that the linked list stores the information of those nodes at the end of the edge starting from node a, and their order only indicates the order of reading information.
If we talk about the edge linked list of node a, it means that the linked list stores the information of those starting points whose end points are node a, and their order only indicates the order of reading information.

If you use a linked list to store Graph Information, you need to create or delete a linked list. These operations involve linked lists. It is easier to understand the structure hierarchy of the adjacent linked list.

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.