public class spartarray }}
system.out.println(sum);
//2.建立對應的稀疏陣列
int sparsearr=new int[sum+1][3];
sparsearr[0][0]=11;
sparsearr[0][1]=11;
sparsearr[0][2]=sum;
//遍歷二維陣列,把二維陣列裡的值放到稀疏陣列
int count=0;
for (int i = 0; i < 11; i++) }}
system.out.println();
system.out.println("得到的稀疏陣列:");
for (int i = 0; i < sparsearr.length; i++)
//讀取稀疏陣列的第一行
int chessarr2 =new int[sparsearr[0][0]][sparsearr[0][1]];
system.out.println("恢復後的二維陣列");
for (int i = 1; i < sparsearr.length; i++)
printarr(chessarr2);
}public static void printarr(int arr)
system.out.println();}}
}
普通陣列轉化稀疏陣列
package sparsearray create by author luozhiyuan qq 707530775 qq.com on 2019 08 04.time 23 44 public class sparsearray system.out.println public static...
稀疏陣列的定義和轉化
稀疏陣列 二維陣列 每個元素都是一維陣列 int arr new int 10 10 0 1 2 3 4 5 6 7 8 9 0 0,0,0,0,0,0,0,0,0,0 1 0,0,1,0,0,0,0,0,0,0 2 0,0,2,0,0,0,0,0,0,0 3 0,2,0,0,0,0,0,0,0,0...
稀疏陣列轉化二維陣列
public class sparse system.out.println system.out.println 轉化為稀疏陣列儲存 獲取有效值的個數 判斷是否有值 int sum 0 臨時變數,計數用的 for int i 0 i 9 i system.out.println 有效值的個數 su...