-
-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathsparseMatrix.cpp
More file actions
50 lines (48 loc) · 797 Bytes
/
sparseMatrix.cpp
File metadata and controls
50 lines (48 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<iostream>
using namespace std;
class element{
public:
int i,j,x;
};
class sparse{
int m,n,num;
element *ele;
public:
sparse(int m,int n,int num){
this->m=m;
this->n=n;
this->num=num;
ele=new element[this->num];
}
~sparse(){
delete [] ele;
}
void read(){
cout<<"Enter the non zero elements"<<endl;
for (int i = 0; i < num; i++)
{
cin>>ele[i].i>>ele[i].j>>ele[i].x;
}
}
void display(){
int k=0;
for (int i = 0; i < m; i++)
{
for (int j = 0; j < n; j++)
{
if(ele[k].i==i&&ele[k].j==j)
cout<<ele[k++].x<<" ";
else
cout<<"0 ";
}
cout<<endl;
}
}
};
int main(){
sparse s(5,5,5);
s.read();
cout<<endl;
s.display();
return 0;
}