当前位置:网站首页>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();
}
}
}
边栏推荐
- 99乘法表
- STM32L4系列单片机ADC通过内部参考电压精确计算输入电压
- [North Asia data recovery] data recovery case of ibm-ds3512 storage server RAID5 damaged data loss
- [linear algebra] 1.1 second and third order determinants
- Gartner“客户之声”最高分,用户体验成中国数据库一大突破口
- [together with Shangshui Shuo series] day 6-strong liver academic paper! The most detailed explanation!
- Lanbao sensor technology rushes to the scientific innovation board: annual revenue of 350million yuan xuyongtong family has a strong color
- Digital twin application of smart Park Based on Web GIS aerial photography
- allegro对走好的线取消走线的方法
- FarrowTech的无线传感器采用橙群微电子的NanoBeacon蓝牙信标技术
猜你喜欢

2022-2028 global secondary butyl lithium industry research and trend analysis report

FPGA(七)RTL代码之三(复杂电路设计2)

Analytic hierarchy process (AHP)

LabVIEW generate application (exe) and installer

问题——adb shellerror: insufficient permissions for device: verify udev rules.

18. ` BS object. Nom du noeud. Suivant Sibling ` get Brother Node
![[together with Shangshui Shuo series] day 6-strong liver academic paper! The most detailed explanation!](/img/70/595a94ba19d29a56a4f0bb5964a199.png)
[together with Shangshui Shuo series] day 6-strong liver academic paper! The most detailed explanation!
![[Algèbre linéaire] 1.1 déterminant du deuxième et du troisième ordre](/img/ea/70b59c64d3287a887e371a9181fe45.png)
[Algèbre linéaire] 1.1 déterminant du deuxième et du troisième ordre

SQL continuous login problem

FPGA(八)RTL代码之四(基本电路设计1)
随机推荐
In the name of love, fresh e-commerce companies rush to sell flowers on Valentine's Day
【云原生】这么火,你不来了解下?
How does sound amplify weak sounds
Yyds dry inventory difference between bazel and gradle tools
Logarithmic calculation in reverse order, logarithmic calculation in sequence -- merge sort
Matlab exercises - image drawing exercises
[linear algebra] 1.1 second and third order determinants
逆序对对数计算,顺序对对数计算——归并排序
2022-2028 global CAE engineering service industry research and trend analysis report
嵌入式开发如何进行源代码保密工作
Leetcode counts the logarithm of points that cannot reach each other in an undirected graph
2022-2028 global secondary butyl lithium industry research and trend analysis report
2022-2028 global long wave infrared camera and camera core industry research and trend analysis report
Concise words tell about technical people who must master basic IT knowledge and skills. Part 1
18. `bs object Node name next_ Sibling` get sibling nodes
Stm32l4 Series MCU ADC accurately calculates input voltage through internal reference voltage
Jerry's watch begins to move [chapter]
18. ` BS object. Nom du noeud. Suivant Sibling ` get Brother Node
使用gdb添加断点的几种方式
[线性代数] 1.2 全排列和对换