当前位置:网站首页>05 use of array
05 use of array
2022-04-23 07:49:00 【Night sky】
Sparse array
A two-dimensional array , Most of the values are defaults , A few cases with other values , Can be converted into sparse array storage , Reduce storage space , Time for space ,
The first row of the sparse array stores the size of the original array and the number of values
The remaining lines store the location information of the special value and the content of the value
0 0 0 0 0 0 0 0 0 0 0
0 0 1 0 0 0 0 0 0 0 0
0 0 0 2 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
The number of valid values :2
That's ok Column value
11 11 2
1 2 1
2 3 2
int[][] eleven = new int[11][11];
eleven[1][2] = 1;
eleven[2][3] = 2;
// Output original array
for (int[] ints : eleven) {
for (int anInt : ints) {
System.out.print(anInt+"\t");
}
System.out.println();
}
// Convert to a sparse array
int sum = 0;
for (int[] ints : eleven) {
for (int anInt : ints) {
if (anInt != 0) {
sum++;
}
}
}
System.out.println(" The number of valid values :"+sum);
int[][] trans = new int[sum+1][3];
trans[0][0] = 11;
trans[0][1] = 11;
trans[0][2] = sum;
int temp = 1;
for (int i = 0; i < eleven.length; i++) {
for (int j = 0; j < eleven[i].length; j++) {
if (eleven[i][j]!=0){
trans[temp][0] = i;
trans[temp][1] = j;
trans[temp][2] = eleven[i][j];
temp++;
}
}
}
System.out.print(" That's ok "+"\t");
System.out.print(" Column "+"\t");
System.out.print(" value "+"\t");
System.out.println();
for (int[] ints : trans) {
for (int anInt : ints) {
System.out.print(anInt+"\t");
}
System.out.println();
}
版权声明
本文为[Night sky]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230627211131.html
边栏推荐
- .NET 5 的新功能 What‘s new in .NET 5
- js之自定义属性以及H5中如何判断自定义属性
- Use of typescript dictionary
- Unityshader Foundation
- 大学学习路线规划建议贴
- Window10版MySQL设置远程访问权限后不起效果
- SampleCameraFilter
- js之排他思想及案例
- SAP 03-AMDP CDS Table Function using ‘WITH‘ Clause(Join子查询内容)
- Unity ugui determines the solution of clicking on the UI and 3D objects
猜你喜欢

js之排他思想及案例

Dictionary & lt; T1,T2&gt; Sorting problem

向量到一个平面的投影向量

SAP CR传输请求顺序、依赖检查

对复杂字典Dictionary&lt;T1,T2&gt;排序问题

Shapley Explanation Networks

Window10版MySQL设置远程访问权限后不起效果

FUEL: Fast UAV Exploration using Incremental Frontier Structure and Hierarchical Planning

Protobuf 使用

Page dynamic display time (upgraded version)
随机推荐
IDEA快捷键
instanceof的实现原理
NodeJS(二)同步读取文件和异步读取文件
.NET 5 的新功能 What‘s new in .NET 5
js中对象的三种创建方式
取得所有点列表中的最大值GetMaxPoint
TimelineWindow
C SVG path parser of xamarin version
url转成对象
防抖和节流
SampleCameraFilter
UnityShader基础
读取修改resource文件夹下的json文件
根据某一指定的表名、列名及列值来向前或向后N条查相关列值的SQL自定义标量值函数
Robust and Efficient Quadrotor Trajectory Generation for Fast Autonomous Flight
保研准备经验贴——18届(2021年)中南计科推免到浙大工院
C#使用拉依达准则(3σ准则)剔除异常数据(.Net剔除一组数据中的奇异值)
canvas学习第一篇
Solve the problem of deploying mysql8 in docker with correct password but unable to log in to MySQL
C# 文本文件的查找及替换(WinForm)