#include <iostream>
using namespace std;typedef int ElemType;void SymmetricMatrixStore(int n, ElemType*& s);//存储n行的对称矩阵,将存储结果放入数组s中返回
void TraverseSymmetricMatrix(ElemType* s, int n);//将存储在数组s中的n行对称矩阵遍历void UpperTriangularMatrixStore(int n, ElemType*& s);//存储n行的上三角矩阵,将存储结果放入数组s中返回
void TraverseUpperTriangularMatrix(ElemType* s, int n);//将存储在数组s中的n行上三角矩阵遍历void LowerTriangularMatrixStore(int n, ElemType*& s);//存储n行的下三角矩阵,将存储结果放入数组s中返回
void TraverseLowerTriangular(ElemType* s, int n);//将存储在数组s中的n行下三角矩阵遍历void TridiagonalMatrixStore(int n, ElemType*& s);//存储n行的三对角矩阵,将存储结果放入数组s中返回
void TraverseTridiagonalMatrix(ElemType* s, int n);//将存储在数组s中的n行三对角矩阵遍历void SymmetricMatrixStore(int n, ElemType*& s) {s = new ElemType[n * (n + 1) / 2];if (!s)exit(0);int length = n * (n + 1) / 2;cout << "请按行顺序输入对称矩阵的值:" << endl;for (int i = 0; i < length; i++)cin >> s[i];
}
void TraverseSymmetricMatrix(ElemType* s, int n) {int k = 0;cout << "---------对称矩阵---------" << endl;for (int i = 0; i < n; i++) {for (int j = 0; j < n; j++) {if (i >= j)k = i * (i + 1) / 2 + j;else k = j * (j + 1) / 2 + i;cout << s[k] << "  ";}cout << endl;}cout << "--------------------------" << endl;
}
void UpperTriangularMatrixStore(int n, ElemType*& s) {s = new ElemType[n * (n + 1) / 2 + 1];if (!s)exit(0);int length = n * (n + 1) / 2;cout << "请按行顺序输入上三角矩阵的三角部分值:" << endl;for (int i = 0; i < length; i++)cin >> s[i];cout << "请输入一位下三角区元素:"; cin >> s[length];
}
void TraverseUpperTriangularMatrix(ElemType* s, int n) {int k = 0;cout << "---------上三角矩阵---------" << endl;for (int i = 0; i < n; i++) {for (int j = 0; j < n; j++) {if (i > j)k = n * (n + 1) / 2;else k = i * (2 * n - i + 1) / 2 + (j - i);cout << s[k] << "  ";}cout << endl;}cout << "----------------------------" << endl;
}
void LowerTriangularMatrixStore(int n, ElemType*& s) {s = new ElemType[n * (n + 1) / 2 + 1];if (!s)exit(0);int length = n * (n + 1) / 2;cout << "请按行顺序输入下三角矩阵的三角部分值:" << endl;for (int i = 0; i < length; i++)cin >> s[i];cout << "请输入一位上三角区元素:";cin >> s[length];
}
void TraverseLowerTriangular(ElemType* s, int n) {int k = 0;cout << "---------下三角矩阵---------" << endl;for (int i = 0; i < n; i++) {for (int j = 0; j < n; j++) {if (i < j)k = n * (n + 1) / 2;else k = i * (i + 1) / 2 + j;cout << s[k] << "  ";}cout << endl;}cout << "----------------------------" << endl;
}
void TridiagonalMatrixStore(int n, ElemType*& s) {s = new ElemType[3 * n - 2];if (!s)exit(0);int length = 3 * n - 2;cout << "请按行顺序输入三对角矩阵的值:" << endl;for (int i = 0; i < length; i++)cin >> s[i];
}
void TraverseTridiagonalMatrix(ElemType* s, int n) {int k = 0;cout << "---------下三角矩阵---------" << endl;for (int i = 0; i < n; i++) {for (int j = 0; j < n; j++) {if (j - i >= -1 && j - i <= 1) {cout << s[k] << "  ";k++;}elsecout << 0 << "  ";}cout << endl;}cout << "----------------------------" << endl;
}int main()
{int n = 0;cout << "请输入矩阵维数:";cin >> n;int* s;SymmetricMatrixStore(n, s);TraverseSymmetricMatrix(s, n);delete[] s;UpperTriangularMatrixStore(n, s);TraverseUpperTriangularMatrix(s, n);delete[] s;LowerTriangularMatrixStore(n, s);TraverseLowerTriangular(s, n);delete[] s;TridiagonalMatrixStore(n, s);TraverseTridiagonalMatrix(s, n);delete[] s;return 0;
}

实验样例

数据结构-特殊矩阵【对称矩阵、上三角下三角矩阵、三对角矩阵】的压缩存储代码实现相关推荐

  1. python 下三角矩阵_Python | 矩阵的上三角

    python 下三角矩阵 A matrix can be seen in different ways and one of them is the upper triangular matrix p ...

  2. 20211115 任意n阶方阵均与三角矩阵(上三角或者下三角)相似

    设 A\boldsymbol{A}A 为 nnn 阶矩阵, 它的特征多项式为 φ(λ)=det⁡(λI−A)=(λ−λ1)(λ−λ2)⋯(λ−λn)\varphi(\lambda)=\operator ...

  3. 用numpy操作矩阵,上三角,下三角矩阵,对角化矩阵

    学习笔记,仅供参考,有错必纠 转载自:https://blog.csdn.net/liuchenbaidu/article/details/108220475 numpy 操作矩阵的意义 1.可以理解 ...

  4. java之上三角矩阵_矩阵化为阶梯矩阵、上三角、下三角矩阵的方法

    一.用初等行变换化行最简形的技巧1. 一般是从左到右,一列一列处理 2. 尽量避免分数的运算 具体操作: 1. 看本列中非零行的首非零元 若有数a是其余数的公因子, 则用这个数把第本列其余的数消成零. ...

  5. python画相关性可视化图上三角_完成这50个Matplotlib代码,你也能画出优秀的图表...

    Matplotlib 是 Python 的绘图库.它可与 NumPy 一起使用,提供了一种有效的 MatLab 开源替代方案,也可以和图形工具包一起使用.和 Pandas.Numpy 并成为数据分析三 ...

  6. 特殊矩阵——对称矩阵(Symmetric Matrix)

    特殊矩阵--对称矩阵(Symmetric Matrix) 注:压缩存储的矩阵可以分为特殊矩阵和稀疏矩阵.对于那些具有相同元素或零元素在矩阵中分布具有一定规律的矩阵,被称之为特殊矩阵.对于那些零元素数据 ...

  7. C/C++实现上、下三角矩阵的压缩存储

    存储思路 上.下三角的压缩存储和对称矩阵的压缩存储(上三角部分.下三角部分)类似,不过是多了一个常数要存储. 对称矩阵的压缩存储 代码 #include <iostream>using n ...

  8. c语言对称矩阵的压缩存储_线性代数(三) 特殊矩阵

    本文将以知识点的形式展开介绍,读者可根据需要自动跳转至相应部分,具体内容如下: (1)单位矩阵(2)对称矩阵(3)对角矩阵(4)正交矩阵(5)伴随矩阵(6)可逆矩阵(7)奇异矩阵(8)初等矩阵(9)行 ...

  9. c++矩阵转置_C语言:数据结构-稀疏矩阵的压缩存储

    (1)稀疏矩阵的特点 在一个m×n的矩阵中,设矩阵中有i个元素不为零,并令△=i/(m×n),称△为稀疏因子.通常当△≤0.05时.认为该矩阵为稀疏矩阵. 对这类矩阵实现压缩存储的基本思路是只需要存储 ...

最新文章

  1. 2022-2028年中国氨基酸表面活性剂行业研究及发展前瞻报告
  2. 机器学习中的聚类算法(2):Mean Shift算法
  3. 目标检测|SSD原理与实现
  4. linux jar命令找不到 -bash: jar: command not found
  5. 7天攻克运维瓶颈 玩转立体运维
  6. 一种新的在线学习的方法:能够克服单人多任务学习的困难!
  7. 【Python】25个好用到爆的一行Python代码,建议收藏
  8. .jar中没有主清单属性_IDEA中spring boot helloword打包运行-0228-2020
  9. 使用CEfSharp之旅(8)CEFSharp 使用代理 更换位置IP
  10. PMAC运动程序例程(一)
  11. Npgsql使用入门(三)【批量导入数据】
  12. POSIX:可移植操作系统接口(Portable Operating System Interface of UNIX,缩写为 POSIX )
  13. 某些服务在未由其他服务或程序使用时将自动停止
  14. IntelliJ IDEA 2021 for Mac(最好的java开发工具)正式版支持m1芯片
  15. 7.企业安全建设入门(基于开源软件打造企业网络安全) --- 蜜罐与攻击欺骗
  16. 计算机应该玩什么游戏,电脑玩游戏主要靠什么配置
  17. 海康iv4200支持多少_安防工程神器-海康安防计算器功能介绍
  18. 2019最全大数据学习资源整理(值得收藏)
  19. 为什么项目经理都需要PMP认证?
  20. Unity2D游戏开发—— 解决主角连跳小BUG(在空中无限跳)

热门文章

  1. python cerberus Validator参数校验
  2. 微型计算机2017年3月上,2017年3月份规模以上工业增加值增长7.6%
  3. Top 7 PHP Security Blunders
  4. 原生js获取本地ip地址(自己用)
  5. activiti适配人大金仓数据库修改方法
  6. 为什么学习Python?数据给你八大理由
  7. 干货推荐|Java并发编程核心概念一览,面试必备!
  8. 西电数据挖掘实验1——二分网络上的链路预测
  9. java中 一个等于号和两个等于号三个等号的区别?
  10. 人工智能之父,你知道是谁吗?