First Encounter with Generalized Lists and Multilinked Lists

发表于 2020-02-27 01:18 364 字 2 min read

cos avatar

cos

FE / ACG / 手工 / 深色模式强迫症 / INFP / 兴趣广泛养两只猫的老宅女 / remote

文章介绍了广义表作为线性表的推广,允许元素为单元素或另一个广义表,并阐述了多重链表的概念及其在存储复杂数据结构中的应用。以稀疏矩阵为例,通过十字链表实现高效存储,只保存非零元素,并利用行指针、列指针和标识域实现矩阵的有序链接与管理。

This article has been machine-translated from Chinese. The translation may contain inaccuracies or awkward phrasing. If in doubt, please refer to the original Chinese version.

I. Generalized Lists

  • A generalization of linear lists
  • In a linear list, all n elements are basic single elements
  • In a generalized list, these elements can be not only single elements but also another generalized list
> typedef struct GNode *GList; struct GNode {
>     int Tag;    //标志域:0表示结点是单元素,1表示结点是广义表
>     union {     //子表指针域SubList域单元素数据域Data复用,共用存储空间
>         ElementType Data;
>         GList SubList;
>     } URegion;
>     GList Next;     //指向后继结点 };

II. Multilinked Lists

  • Nodes in a list may belong to multiple chains

Nodes in a multilinked list have multiple pointer fields, as in the previous example which contains Next and SubList; However, a list with two pointer fields is not necessarily a multilinked list — for example, a doubly linked list is not a multilinked list

  • Multilinked lists have a wide range of applications:

Relatively complex data structures such as trees and graphs can generally be implemented using multilinked lists for storage

Example: Storing Matrices

Using a two-dimensional array has two drawbacks

  • First, the size of the array needs to be determined in advance
  • Second, for sparse matrices, it causes a large waste of storage space

Analysis: Use a typical multilinked list — orthogonal linked list to store sparse matrices Only store non-zero elements

  • Pointer fields of a node: Row coordinate Row, column coordinate Col, value Value
  • Each node is linked through two pointer fields to connect nodes in the same row and same column: Row pointer (or right pointer) Right Column pointer (or down pointer) Down
  • A tag field Tag is used to distinguish between head nodes and non-zero element nodes: The tag value for head nodes is “Head”, and the tag value for non-zero element nodes is “Term”

喜欢的话,留下你的评论吧~

© 2020 - 2026 cos @cosine
Powered by theme astro-koharu · Inspired by Shoka