Sparse Matrix as a Linked-list & Template (4 types)

Hi guys ,
Given the following code , the h. file of my template LinkedList

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    template <class T>
    class LinkedList {
    
    protected:
    
            class Node              
            {
            public:
                    int row;                
                    int col;                
                    T value;                
                    Node *next;     
    
            };
    
            Node * head;                  // the head of the matrix
    
    public:
            LinkedList();
            ~LinkedList();
            void addNewNodeToLL(const T& value, ......) 
    };

I need to create a Template Linked list , that would support the following types :
int ,char,double ,bool .
I have a class called Menu that gets inputs from the user , and create nodes accordingly.

What data I'd store? the linked-list is supposed to represent a Sparse-Matrix , i.e. (instead of
NxN two dimensional array , since it's a lot of memory that is being used for cells that would
probably contain nothing ) would store only the cells that has some value other than an empty cell (ZEROs for example).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Menu.h


    class Menu{
    
    private:
            LinkedList<int> *list1
            LinkedList<char> *list2
            LinkedList<double> *list3 
            LinkedList<bool> *list4;
    
    public:
    
            void insertValuesToMatrix();
    ...
    ...
    // some more code ,irrelevant for the moment
    
    
    }



The problem is , that I need to create templated nodes , and not a specific
node (for exmaple :int) but I don't know how to do that.
I have the method "void insertValuesToMatrix();" , that hopefully would create nodes ,
but how can I have a pointer of T type , and not double/int/bool/char (as you can see in the private of Menu class) .
From what I've been trying for the last few hours ,I wasn't able to create a general pointer
for the LinkedList as Template.

I'd appreciate any help ,
Thanks,Ron
Last edited on
Are you familiar with variant types?

Or you could implement different types of nodes the types you want to hold (nt ,char,double ,bool).

Do you really want to store all those types in a single matrix at the same time?
Last edited on
Topic archived. No new replies allowed.