![]() |
problem with node implementation
Hi ,
I have problems implementing my mnode class for an implementation of a sparse matrix: :
#include <string>I have not started implementing the matrix class but I have tons of weird errors for what I have done. Errors are like 'aNode undeclared' or 'specific undeclared.'. and ISO C++ forbids declaration of `string' with no type Also I dont know if my reasonning is all right for the functions I wrote. Can someone help me with some guidance? B. |
You can' just put in "include <string>". The name isn't known. Put "using std::string;" up there at the top. Stuff like that.
|
Yeah ,
I forgot a bunch of thing in it. I just 2 errors here in red at the indicated lines. :
class matrixThe first error bugs me a little. EDIT: IGET THE FIRST ERROR!! B |
Your nodeData function is const but you have it return a non-const reference to an internal variable. I suppose you either need to make the return type a "const float&" or perhaps just return a copy of data. The correct choice depends on you needs.
|
Dont you need to put ';' after class matrix??????
|
Hi,
I have a problem implementing sparse matrix.I want to create the header nodes but I just can't find the solution. this is what I have done: This is the mnode class: :
//#include"matrix.h"Note the pointer float* a is a pointer of a 2-dim full matrix .It is ONLY used to provide information to the constructor to construct the sparse matrix object and must not be used after that in the program. the class matrix: :
class matrixThe implementation for the mnode compile ok(but not sure if right) The compilation for matrix is not comiling well. Too much errors are in there . My second problem is How to use the float * a to store the non-zero element innthe sparse matrix.,how to find the correct header and insert the data at the good place. Can I have some help for this? I am struggling on it for several days now. Thank you. B |
One way, not necessarily the most efficient, but the most useful, would be to write a method that allows you to insert a value at any location. Then looping through the a array and inserting each non-zero value would be easy.
The insert method would have to do the following: - create a new mnode with the value in it - loop through the column headers from head->right to find the column - loop down that column (using ->down) to find the right row - insert the mnode at that point (or replace the value that is already there) - if the value wasn't already in the sparse array: - loop through the row headers from head->down to find the row - loop right along that row to find the right column - insert the mnode at that point This is all just off the top of my head, and I haven't tried to implement it. |
Looking at the mnode code:
:
float& mnode::nodeData() //const:
void mnode::set(const string& specific, mnode* aNode) |
Thank you Dark.
I will work on the modifications and the insert method. |
Hi,
I am trying to implemement the operator * to multiply two sparse matrix. I need some guidance to code it. the fact that the zero elements are not stored make it difficult. Please can someone help me? I recall the two classes below : thank you. matrix.h :
class matrixmnode.h :
class mnode |
| All times are GMT -5. The time now is 2:01 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC