如何在链接列表中存储数字列表

How to store a list of numbers in a link list

本文关键字:列表 数字 存储 链接      更新时间:2023-10-16

我一直在尝试将数组的数字存储在链接列表中。但我不知道该怎么做。我需要有人帮我完成代码。

#include <iostream>

using namespace std;
int main()
{
    int numeros[9] = {1,2,3,4,5,6,7,8,9};
    typedef struct Node *NodePtr; //declara Nodeptr un apuntador a Node
    struct Node
    {
        int x;
        Node *next; // omit the 'struct' for C++-only usage
    };
    return 0;  
}

压缩方式:

struct Node
{
    int x;
    Node *next;
} nodes[] = {
    {1, nodes + 1},
    {2, nodes + 2},
    {3, nodes + 3},
    {4, nodes + 4},
    {5, nodes + 5},
    {6, nodes + 6},
    {7, nodes + 7},
    {8, nodes + 8},
    {9, nullptr}
};
Node* root = nodes;
相关文章: