当前位置:网站首页>Linear and nonlinear structures
Linear and nonlinear structures
2022-06-29 03:13:00 【Bald headed talent】
Linear structure and nonlinear structure

Because many of the default values for two-dimensional arrays are 0, So a lot of meaningless data was recorded –> Sparse array 
Illustrate with examples :
Application example :
Array conversion analysis :
public class demo {
public static void main(String[] args) {
// Create an original 11*11 Two dimensional array of
//0 No chess pieces 1 White chess 2 Indicates blue chess
int chessArr1[][] = new int[11][11];
chessArr1[1][2] = 1;
chessArr1[2][3] = 2;
// Output the original two-dimensional array
System.out.println(" The original two-dimensional array :");
for (int[] row : chessArr1) {
for (int data : row) {
System.out.printf("%d\t", data);
}
System.out.println();
}
// The idea of converting a two-dimensional array into a sparse array
//1. First, traverse the two-dimensional array Get the blame 0 The number of data
int sum = 0;
for (int i = 0; i < 11; i++) {
for (int j = 0; j < 11; j++) {
if (chessArr1[i][j] != 0) {
sum++;
}
}
}
//2. Create the corresponding sparse array
int sparseArr[][] = new int[sum + 1][3];
// Assign values to sparse arrays
sparseArr[0][0] = 11;
sparseArr[0][1] = 11;
sparseArr[0][2] = sum;
//3. Traversing a two-dimensional array Will not 0 Data stored in sparseArr in
int count = 1;// Used to record the number of non 0 data
for (int i = 0; i < 11; i++) {
for (int j = 0; j < 11; j++) {
if (chessArr1[i][j] != 0) {
sparseArr[count][0] = i;
sparseArr[count][1] = j;
sparseArr[count][2] = count;
count++;
}
}
}
// Output sparse array form
System.out.println();
System.out.println(" The resulting sparse array is :");
for (int i=0;i<sparseArr.length;i++) {
System.out.printf("%d\t%d\t%d\t", sparseArr[i][0],sparseArr[i][1],sparseArr[i][2]);
System.out.println();
}
// Restore the sparse array to the original two-dimensional array
//1. First read the first row of the sparse array , According to the data in the first line , Create the original two-dimensional array
int[][] chessArr2=new int[sparseArr[0][0]][sparseArr[0][1]];
//2. A few lines after reading the sparse array ( Start with the second line ) data , And assign it to the original two-dimensional array
for (int i=1;i<sparseArr.length;i++){
chessArr2[sparseArr[i][0]][sparseArr[i][1]]=sparseArr[i][2];
}
// Output the recovered 2D array
System.out.println();
for (int[] row : chessArr2) {
for (int data : row) {
System.out.printf("%d\t", data);
}
System.out.println();
}
}
}
边栏推荐
- Provide ideas in old texts
- LabVIEW generate application (exe) and installer
- 层次分析法(AHP)
- [leetcode daily question] number of schemes to reconstruct a tree
- PWN attack and defense world level2
- Analytic hierarchy process (AHP)
- In depth analysis of Apache bookkeeper series: Part 3 - reading principle
- FPGA(七)RTL代码之三(复杂电路设计2)
- matlab习题 —— 图像绘制练习
- Solve the problem that the cursor flashes after clicking a point when measuring the distance in Allegro
猜你喜欢

PWN攻防世界Level2
![[線性代數] 1.1 二階與三階行列式](/img/ea/70b59c64d3287a887e371a9181fe45.png)
[線性代數] 1.1 二階與三階行列式
![Jerry's watch obtains alarm mode settings [chapter]](/img/43/987d864ec6038b10138ce50bcbdf12.jpg)
Jerry's watch obtains alarm mode settings [chapter]

双击事件与单击事件的那些事

Redu.us took the initiative to transform, and the operation leader of China's charging pile emerged
![[North Asia data recovery] data recovery case of ibm-ds3512 storage server RAID5 damaged data loss](/img/84/c8604f539db4658049406080d7f09a.jpg)
[North Asia data recovery] data recovery case of ibm-ds3512 storage server RAID5 damaged data loss

2022-2028 global low carbon concrete industry research and trend analysis report

PWN attack and defense world level2

微信小程序安全登录,必须先校验微信返回openid,确保信息唯一性。

问题——adb shellerror: insufficient permissions for device: verify udev rules.
随机推荐
Setting alarm mode of Jerry's watch [chapter]
嵌入式开发如何进行源代码保密工作
蓝桥杯2022初赛——扫雷
Merge sort
[Algèbre linéaire] 1.1 déterminant du deuxième et du troisième ordre
[线性代数] 1.2 全排列和对换
Several ways to add breakpoints using GDB
【一起上水硕系列】Day 6-强肝学术论文!最细解释!
18. `bs對象.節點名.next_sibling` 獲取兄弟節點
测试入门——集成测试
How to optimize databases and tables
Jerry's watch begins to move [chapter]
Digital twin application of smart Park Based on Web GIS aerial photography
Problème - Ajouter shellerror: permissions d'instrumentation pour le périphérique: vérifier les règles udev.
How to skip time when closing a socket connection_ Wait status of wait
Is it safe to open a stock account by mobile phone? Is it difficult to open an account?
SQL continuous login problem
[線性代數] 1.1 二階與三階行列式
allegro设置网络飞线以及网络颜色的方法
STM32L4系列单片机ADC通过内部参考电压精确计算输入电压