Thread: Create Sparse Matrix

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    10

    Create Sparse Matrix

    I need build function that creates a structure for sparse empty matrix (that in entirety nils ) and returns pointer to the created structure

    I need to use the functions malloc in order to create a new member from type Cell, and the address that received to return, after zeroed the member in order that will adapt to the head of the structure (line of nil, column of nil, and nullification pointersof to the right and down )

    how to write this algorithm , somebody help!

    Code:
    #include <stdlib.h>
    #include <stdio.h>
    
    typedef int Elem;
    typedef struct cell Cell;
    typedef Cell * Matrix;
    
    struct cell {
    	int row;
    	int col;
    	Cell * right;
    	Cell * down;
    	Elem value;
    };
    Code:
    newSparseMatrix ()
    {
    ....
    }

  2. #2
    Registered User
    Join Date
    Feb 2009
    Posts
    138
    so you do the easy work and want someone else to do the hard work? the best way to figure it out is to try it.

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    10
    I think it is necessary to make so but is not assured of it

    Code:
    Matrix newSparseMatrix(){
    
    	A = (*Cell)malloc(sizeof(Cell));
    	Matrix A->row = NULL;
    	Matrix A->col = NULL;
    	Matrix A->row = NULL;
    	return A;
    }

  4. #4
    Registered User
    Join Date
    Jan 2009
    Posts
    10
    If I learn as correctly it to make, it will solve to me all problems

  5. #5
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    having a hard time following your post
    malloc() an object of type struct cell each of whose elements are NULL and return a pointer to that object? have I got it or am I totally off?

  6. #6
    Registered User
    Join Date
    Jan 2009
    Posts
    10
    I have not so understood a question

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    So you've got five things to set (four if you don't care about the value).

  8. #8
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    calloc() is a better choice if all you want to do is create a matrix with a "hole" in it as calloc() resets all bits.

  9. #9
    Registered User
    Join Date
    Jan 2009
    Posts
    10
    I can`t use calloc ()

  10. #10
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Be able, I might, to provide an answer, if the question, I could, understand!
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  11. #11
    Ex scientia vera
    Join Date
    Sep 2007
    Posts
    477
    Quote Originally Posted by iMalc View Post
    Be able, I might, to provide an answer, if the question, I could, understand!
    Google translate for the win!
    "What's up, Doc?"
    "'Up' is a relative concept. It has no intrinsic value."

  12. #12
    Registered User
    Join Date
    Feb 2009
    Posts
    1

    void freeSparseMatrix( Matrix m )

    i am stuck with the same assgiment....but with a diffrent part....
    can some one healp with the void freeSparseMatrix( Matrix m )

    thanks ahead....

  13. #13
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    It would better to open a new thread of your own.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sparse Matrix
    By brb9412 in forum C Programming
    Replies: 3
    Last Post: 01-02-2009, 01:12 PM
  2. Replies: 1
    Last Post: 03-08-2006, 06:47 PM
  3. Matrix and vector operations on computers
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 05-11-2004, 06:36 AM