1.稀疏数组
- 当一个数组中大部分元素为0,或者为同一个值的时候,可以用稀疏数组来保存该数组。
- 稀疏数组的处理方法:
1.记录数组一共有几行几列,有多少个不同的值
2.把具有不同元素的行列及值记录在一个小规模数组中,从而缩小程序规模。
2,代码实现
/**
* 稀疏数组
*
* @author wangjie
* @version V1.0
* @date 2019/12/18
*/
public class SparseArray {
public static void main(String[] args) {
int[][] chessArr1 = new int[11][11];
chessArr1[1][2] = 1;
chessArr1[5][5] = 2;
print(chessArr1);
int[][] ints = arrayToSparseArray(chessArr1);
print(ints);
int[][] ints1 = sparseArrayToArray(ints);