以平衡的方式将值从地图分配到数组

时间:2013-09-22 09:09:59

标签: java arrays map

我正在尝试获得一种平衡算法,但很难理解如何实现这一点。

我有一个HashMap如下:

Map criteria = new HashMap();
criteria.put("0",5);
criteria.put("1",8);
criteria.put("2",0);
criteria.put("3",7);
...

另外,我有一个二维数组,我需要从HashMap获取值并以平衡的方式放入数组。

String[][] arr = new String[3][1];

我正在寻找的最终结果是这样的:

arr[0][0]="0"; (the key of the hashmap)
arr[1][0]="1";
arr[2][0]="2,3"; (as the key "2" has the value less among the first two entries, the key "3" should be appended top this node)

因此,基本上HashMap的键应该根据其值均匀分布到Array中。

非常感谢您的帮助。

0 个答案:

没有答案
相关问题