안선생의 개발 블로그

메트릭스2 본문

알고리즘

메트릭스2

안선생 2022. 11. 27. 16:41
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <iostream>
using namespace std;
class Matric { // 대각선 행렬
private:
    int* A;
    int n; //열수
public:
    Matric()
    {
        n = 2;
        A = new int[2];
    }
    Matric(int n)
    {
        this->= n;
        A = new int[n];
    }
    ~Matric()
    {
        delete[] A;
    }
public:
    void Set(int i, int j, int x);
    int Get(int i, int j);
    void Display();
};
 
void Matric::Set(int i, int j, int x)
{
    if (i == j)
        A[i - 1= x;
}
 
int Matric::Get(int i, int j)
{
    if (i == j)
        return A[i - 1];
    else
        return 0;
}
 
void Matric::Display()
{
    int i, j;
    for (i = 0; i < n; i++)
    {
        for (j = 0; j < n; j++)
        {
            if (i == j)
                cout << A[i]<<" "//0부터 시작하므로 -1을 안해준다.
            else
                cout << "0 ";
        }
        cout << "\n";
    }
}
int main()
{
    Matric m(4);
    
    m.Set(111); m.Set(222); m.Set(333); m.Set(444);
    m.Display();
 
    return 0;
};
cs

'알고리즘' 카테고리의 다른 글

BST  (0) 2022.11.27
AVL Tree  (0) 2022.11.27
C++ 메트릭스  (0) 2022.11.27
C++ tree  (0) 2022.11.16
tree  (0) 2022.11.16