[
next
] [
prev
] [
prev-tail
] [
tail
] [
up
]
sparse matrix
Sparse matrix can implemented by on dimension array or linked list.
template
<
typename
T
>
class
term
{
int
row
,
int
col
;
T
value
;
}
Term
<
T
>
*
sparseMatrix
;
Sparse matrix in linked list.
Three level definition
template
<
typenameT
>
class
CNode
{
int
col
;
T
value
;
};
template
<
typename
T
>
class
HeadNode
{
int
row
,
Chain
<
CNode
<
T
>
>
colFirst
};
template
<
typename
T
>
class
Matrix
{
Chain
<
HeadNode
<
T
>
>
Frist
}
You can build a matrix class. use m(2,3) to access a element. And support +, - * . You also can define index begin from 1. It will more reasonable for you when you use a matrix.
template
<
typename
T
>
class
Matrix
{
T
&
operator
()(
int
row
,
int
col
){
..}
}
[
next
] [
prev
] [
prev-tail
] [
front
] [
up
]