File tree 1 file changed +81
-0
lines changed
1 file changed +81
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < iostream.h>
2
+ #include < conio.h>
3
+
4
+ class sparse
5
+ {
6
+ struct sp
7
+ {
8
+ int r;
9
+ int c;
10
+ int v;
11
+ }
12
+ s[10 ];
13
+ public:
14
+ sparse ()
15
+ {
16
+ s[0 ].r =0 ;
17
+ s[0 ].c =0 ;
18
+ s[0 ].v =0 ;
19
+ }
20
+ void create ()
21
+ {
22
+ cout<<“\n no of rows & columns& elements”;
23
+ cin>>s[0 ].r ;
24
+ cin>>s[0 ].c ;
25
+ cin>>s[0 ].v ;
26
+ for (int i=1 ;i<=s[0 ].v ;i++)
27
+ {
28
+ cout<<“\n row & column & element”;
29
+ cin>>s[i].r ;
30
+ cin>>s[i].c ;
31
+ cin>>s[i].v ;
32
+ }
33
+ }
34
+ void display ()
35
+ {
36
+ cout<<“\n no of rows & columns& elements\n”;
37
+ for (int i=0 ;i<=s[0 ].v ;i++)
38
+ {
39
+ cout<<s[i].r <<“\t”;
40
+ cout<<s[i].c <<“\t”;
41
+ cout<<s[i].v <<“\n”;
42
+ }
43
+ }
44
+ sparse operator +(sparse s2)
45
+ {
46
+ sparse s3;
47
+ int k=1 ;
48
+ s3.s [0 ].r =s[0 ].r ;
49
+ s3.s [0 ].c =s[0 ].c ;
50
+ int i=1 ,j=1 ;
51
+ while (i<=s[0 ].v || j<=s2.s [0 ].v )
52
+ {
53
+ if ((s[i].r ==s2.s [j].r )&&(s[i].c ==s2.s [j].c ))
54
+ {
55
+ s3.s [k].r =s[i].r ;
56
+ s3.s [k].c =s[i].c ;
57
+ s3.s [k].v =s[i].v +s2.s [j].v ;
58
+ i++; j++; k++;
59
+ }
60
+ else if ((s[i].r ==s2.s [j].r )&&(s[i].c ==s2.s [j].c ))
61
+
62
+
63
+
64
+ }
65
+ s3.s [0 ].v =k;
66
+ return s3;
67
+ }
68
+ };
69
+ void main ()
70
+ {
71
+ sparse s1,s2,s3;
72
+ s1.create ();
73
+ s2.create ();
74
+ s1.display ();
75
+ s2.display ();
76
+ s3=s1+s2;
77
+ s3.display ();
78
+
79
+ getch ();
80
+ }
81
+
You can’t perform that action at this time.
0 commit comments