开发者

parse 2-D matrix into link-list

开发者 https://www.devze.com 2023-01-28 17:59 出处:网络
Here is the matrix I want to represent in the link-list form The idea is that it\'s a 2-D matrix. The font in red is the regular [i][j], and blue is the extra information I want to store in a link-l

Here is the matrix I want to represent in the link-list form

parse 2-D matrix into link-list

The idea is that it's a 2-D matrix. The font in red is the regular [i][j], and blue is the extra information I want to store in a link-list.

In this matrix, I need to have several informations to be stored.

  1. int row
  2. int colm
  3. int label [as shown in blue]
  4. bool value (the value to be displayed on the screen)
  5. *** right
  6. *** left
  7. *** up
  8. *** down

the problem is i am going to get 4 link-lists, if I create 4 pointers of array [for 2-D matrix]? how do I even get the directional poin开发者_高级运维ters???

If you are curious, I am working on solving a Karnaugh Map. link text

Any help is appreciated. Thanks!


Don't use a linked list, use a 2-d array. Quick & dirty (and incomplete):

struct Matrix {
    struct Entry {
        int label;
        bool value;
    };

    Entry *array;
    size_t rowlen;

    Matrix(int n) : rowlen(n) { array = new Entry[n*n]; }
    ~Matrix() { delete[] array; }

    Entry &at(int i, int j) { return array[i * rowlen + j]; }

    // etc.
};

No need for directional pointers, just use some smart addition and subtraction logic.

0

精彩评论

暂无评论...
验证码 换一张
取 消