Thursday, June 16, 2011

Adding more flexibility, to #include "sparse.cpp"

This is my third blog post regarding #include "sparse.cpp". I have tried to embed more user friendliness this time. display() function is still giving segfaults, and the definitions of retrieve( int, int ) and remove ( int, int ) are not included in the source.

Complete source code(s)

One major change this time: The code is split into header and definition files.

sparse.h:

 /* 
  *  This program is a part of an attempt to implement Sparse
  *  Matrix in C(plus)(plus)
  *
  *  Copyright 2011 Saurabh Araiyer <sizzsa(at)gmail(dot)com>
  *
  *  Licenced under GNU GPL v3+
  *
  *  Downloaded From http://goo.gl/WNrQZ
  */
 

#include <iostream>
#include <vector>
#include "llnode.cpp"

using std::vector;
using std::cout;
using std::cin;   
/*
 * std::cin and cin::cout to be removed in later phase(s) 
 * included for verbose input
 */

#ifndef SPARSE_H
#define SPARSE_H

template <class T>
class sparse
{
public:
    llnode <T> *root;
    sparse(char cVerbose = NULL);
    sparse(vector <T> , vector <int> , vector <int> );
    ~sparse();
    int insert(T , int, int);
    void dispaly();
    void vertical(int);
    void horizontal(int);
    T   retrieve(int, int);         // Input is Array indeces
    int remove  (int, int);         //Synonymous to delete, input is array indeces

private:
    int m,n;
    llnode <T> *temp;
    int maxval(vector<int>);
    int push(T , int, int);
    int index_return(int, llnode <T>*);
    int incase(int, llnode <T>*, int, int);
};

#endif // SPARSE_H

No comments:

Post a Comment