Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8570309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:31:44+00:00 2026-06-11T18:31:44+00:00

I’m coding the program that using linked list to store a sparse matrix. First

  • 0

I’m coding the program that using linked list to store a sparse matrix. First I create a class “Node” contains the index of entry, value of entry and two pointers to next row and next column. Second I find on Google that I need to create the class Matrix like this code below but I don’t understand the meaning of Node **rowList and node** columnList. Why they use a pointer to a pointer there and how could I implement a matrix from that? Thank you so much.

class Node
{
public:
    int iValue, jValue;
    float value;
    Node *rowPtr;
    Node *colPtr;
};

class Matrix
{
    Node **rowList;     // rowList is the pointer to the array of rows
    Node **columnList;  // columnList is the pointer to the array of columns
    int rows, cols;     // number of rows and columns
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T18:31:45+00:00Added an answer on June 11, 2026 at 6:31 pm

    It appears to be exactly what the comment says. They are arrays. Presumably rowList will be an array of rows elements, and columnList will be an array of cols elements. The reason it’s a Node** is that each item in the array is a Node*. A pointer to an array always has an extra level of indirection (an extra *). That means when you index a single element out of that array you get a value of type Node* again.

    The arrays are created like this:

    rowList = new Node* [rows];
    columnList = new Node* [cols];
    
    // Don't forget to initialise the values to NULL!  Here's the dull way:
    for( int i = 0; i < rows; i++ ) rowList[i] = NULL;
    for( int i = 0; i < cols; i++ ) columnList[i] = NULL;
    

    When you need to delete them (in the destructor for Matrix):

    delete [] rowList;
    delete [] colList;
    

    As for your question on how to implement your matrix from that, that’s really up to you. Presumably when you create a node at position (i, j), you append that node to each of rowList and columnList. ie:

    Node * node = new Node(i, j, 123.0);
    rowList[i] = node;
    columnList[j] = node;
    

    But it’s not that simple, because the node obviously must be linked into both a row and column list. At the very basic level, and using the structures you’ve provided, here’s one way:

    // Inserts newNode at the head of the list and modifies the head pointer.
    void insert_row( Node* & r, Node *newNode )
    {
        newNode->rowPtr = r;
        if( r != NULL ) r->rowPtr = newNode;
        r = newNode;
    }
    
    // Similarly with insert_col()...
    

    Now using the above with my original example:

    Node * node = new Node(i, j, 123.0);
    insert_row( rowList[i], node );
    insert_col( columnList[j], node );
    

    For ordered insert

    Since you have code already, I will offer my take on it. But you still need to do some work yourself.

    I just try to understand the concept but it’s so confusing for me.

    Let’s just clean things up to begin with. It’s a class, and you’re using C++ so please use your C++ knowledge:

    class Node
    {
    public:
        Node( int i, int j, int val );
    
        void InsertRowAfter( Node* node );
        void InsertColAfter( Node* node );
    
        int iValue, jValue;  // Row and column index, 1-based
        float value;         // Element value
        Node *rowPtr;        // Next element in this row (sorted by jValue)
        Node *colPtr;        // Next element in this column (sorted by iValue)
    };
    
    Node::Node( int i, int j, int val )
        : iValue(i)
        , jValue(j)
        , value(val)
        , rowPtr(NULL)
        , colPtr(NULL)
    {}
    
    // Inserts the given node to follow this node in the row list
    void Node::InsertRowAfter( Node* node )
    {
        // [go on, you do it]
    }
    
    // Inserts the given node to follow this node in the column list
    void Node::InsertColAfter( Node* node );
    {
        // [go on, you do it]
    }
    

    So, now you need to implement the Matrix::inputData function… Essentially you do what your friend was trying to do, but without the errors and memory leaks. That means you start like this:

    // Use 'horz' and 'vert' to search through the row and column lists.  If a
    // node needs to be created, it will be stored in 'node'.
    Node *horz = rowList[iValue - 1];
    Node *vert = columnList[jValue - 1];
    Node *node;
    
    // If there is no row list or smallest jValue, insert at the head.
    // Otherwise, search for an insert point.
    if( !horz || horz->jValue > jValue )
    {
        // [go on, you do it]
    }
    else
    {
        // Move 'horz' pointer to position at which we will append a node.
        Node *next = horz->rowPtr;
        while( next && next->jValue <= jValue ) {
            horz = next;
            next = next->rowPtr;
        }
    
        // If replacing an existing value, there's nothing else to do.
        if( horz->jValue == jValue ) {
            horz->value = value;
            return;
        }
    
        // Otherwise append a new node.
        // [go on, you do it]
    }
    

    Now, you finish the function off, and don’t forget to do the column indexing…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.