4K+ 阅读量
树遍历是图遍历的一种形式。它涉及到精确检查或打印树中的每个节点一次。二叉搜索树的后序遍历涉及按(左,右,根)的顺序访问树中的每个节点。二叉树的后序遍历示例如下。给定一个二叉树如下。后序遍历为:1 5 4 8 6执行后序递归遍历的程序如下所示。示例 实时演示#include using namespace std; struct node { int data; struct node *left; struct node *right; }; struct node *createNode(int val) ... 阅读更多
14K+ 阅读量
树遍历是图遍历的一种形式。它涉及到精确检查或打印树中的每个节点一次。二叉搜索树的中序遍历涉及按(左,根,右)的顺序访问树中的每个节点。二叉树的中序遍历示例如下。给定一个二叉树如下。中序遍历为:1 4 5 6 8执行中序递归遍历的程序如下所示。示例 实时演示#include using namespace std; struct node { int data; struct node *left; struct node *right; }; struct node *createNode(int val) ... 阅读更多
7K+ 阅读量
树遍历是图遍历的一种形式。它涉及到精确检查或打印树中的每个节点一次。二叉搜索树的前序遍历涉及按(根,左,右)的顺序访问树中的每个节点。二叉树的前序遍历示例如下。给定一个二叉树如下。前序遍历为:6 4 1 5 8执行前序递归遍历的程序如下所示。示例 实时演示#include using namespace std; struct node { int data; struct node *left; struct node *right; }; struct node *createNode(int val) ... 阅读更多
276 阅读量
如果两个矩阵可以相乘,则称它们是可乘的。只有当第一个矩阵的列数等于第二个矩阵的行数时,才有可能。例如。矩阵 1 的行数 = 3 矩阵 1 的列数 = 2 矩阵 2 的行数 = 2 矩阵 2 的列数 = 5 矩阵 1 和矩阵 2 是可乘的,因为矩阵 1 的列数等于矩阵 2 的行数。检查...阅读更多
10K+ 阅读量
可以使用矩阵的元素值来计算方阵的行列式。矩阵 A 的行列式可以表示为 det(A),在几何学中,它可以被称为矩阵描述的线性变换的缩放因子。矩阵行列式的示例如下。矩阵为:3 1 2 7上述矩阵的行列式 = 7*3 - 2*1 = 21 - 2 = 19 所以,行列式为 19。计算矩阵行列式的程序如下所示。示例 实时演示#include #include using namespace std; int determinant( int matrix[10][10], int ... 阅读更多
294 阅读量
矩阵的行列式可以用来判断它是否可逆。如果行列式不为零,则矩阵可逆。因此,如果行列式结果为零,则矩阵不可逆。例如 -给定的矩阵为:4 2 1 2 1 1 9 3 2上述矩阵的行列式为:3 所以矩阵可逆。检查矩阵是否可逆的程序如下所示。示例 实时演示#include #include using namespace std; int determinant( int matrix[10][10], int n) { int det = 0; int ... 阅读更多
2K+ 阅读量
矩阵是以行和列的形式排列的数字的矩形数组。矩阵的示例如下。一个 3*4 矩阵有 3 行 4 列,如下所示。8 6 3 5 7 1 9 2 5 1 9 8通过将矩阵传递给函数来乘以两个矩阵的程序如下所示。示例 实时演示#include using namespace std; void MatrixMultiplication(int a[2][3],int b[3][3]) { int product[10][10], r1=2, c1=3, r2=3, c2=3, i, j, k; if (c1 != r2) { cout
结构是不同数据类型项的集合。它在创建具有不同数据类型记录的复杂数据结构方面非常有用。结构使用 struct 关键字定义。结构的示例如下 -struct employee { int empID; char name[50]; float salary; };使用结构存储和显示信息的程序如下所示。示例 实时演示#include using namespace std; struct employee { int empID; char name[50]; int salary; char department[50]; }; int main() { struct employee emp[3] = { { 1 , "Harry" , 20000 , "Finance" } , { 2 , "Sally" , 50000 , "HR" } , { 3 , "John" , 15000 , "Technical" } }; cout
8K+ 阅读量
标准差是衡量数据中数字分散程度的指标。它是方差的平方根,其中方差是与平均值平方差的平均值。计算标准差的程序如下所示。示例 实时演示#include #include using namespace std; int main() { float val[5] = {12.5, 7.0, 10.0, 7.8, 15.5}; float sum = 0.0, mean, variance = 0.0, stdDeviation; int i; for(i = 0; i < 5; ++i) sum += val[i]; mean = sum/5; for(i = 0; i < 5; ++i) variance += pow(val[i] - mean, 2); variance=variance/5; stdDeviation = sqrt(variance); cout
614 阅读量
稀疏矩阵是指矩阵中大多数元素都为 0 的矩阵。换句话说,如果矩阵中超过一半的元素为 0,则称为稀疏矩阵。例如 - 下面给出的矩阵包含 5 个零。由于零的个数超过了矩阵元素的一半,因此它是一个稀疏矩阵。1 0 2 5 0 0 0 0 9检查它是否为稀疏矩阵的程序如下所示。示例 在线演示#include using namespace std; int main () { int a[10][10] = { {2, ... 阅读更多