Question

Below are the two classes Node List that i came across in the code.

I am unable to visualise this data structure that these two classes collectively are trying to represent.

        class  Node
        {
            private:

                friend class List;

                Node* next ;
                Node* prev ;
                List* listpointer;
                void add ( Node* , List * ) ;




        } ;

        void Node :: add ( Node* predecessor, List *parent )
        {


    } // Node :: add()

    Node* Node :: rem ( void )
    {


     }

} 

class List
{
    private:
        friend class Node;

        Node* head ;
        Node* dummy ;
        Node* tail ;
        int count;

    public:

        List ( void ): dummy( NULL), count( 0 )
        {
        }

        ~List ( void ) ;

        void addhead ( Node* node )
        {

        }

        void addtail ( Node* node )
        {

        }

        Node* gethead ( void ) const
        {

        }

        Node* gettail ( void ) const
        {

        }

        Node* remhead ( void )
        {

        }

        Node* remtail ( void )
        {

        }

        Node* getnode ( int i ) const ;
        int getnodecount ( void ) const ;

        void swap ( Node *node1, Node *node2 ) ;

        Node* removehead ( void )
        {

        }

        Node* removetail ( void )
        {

        }

        CsTboolean is_member ( Node * node ) const
        {

        }

} ;

My question:

Can you please help me visualise this data structure? Is this graph/dlist/somethingelse?

Was it helpful?

Solution

This structure looks like a double linked list.

A linked list can be visualized like a chain of nodes, each node pointing to the next one in the list. In this case it's a double linked list because each node also points toward the previous node as well.

The CsGNode class is simply what an individual node can do. In this case, it knows the previous one, the next one and also links to another list. I'm not sure what for since the void add ( CsGNode* , CsGList * ) ; definition is missing.

The CsGList class is simply holding pointers to the first and last node (head and tail) so as to not lose the data. It's also used to adds the nodes and move them around if needed. The CsGList is the one responsible for the big picture there, while each individual node is only responsible for itself.

You could visualize it as each block being a node, and the list being the tail and head, and using those two pointers to navigate through the list.

badly drawn doubly linked list

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top