mysql索引超出了数组接线_索引超出了数组界限如何解决?

展开全部

索引超出了数组界限解决方法:

a.connected[i] = vertices[i+1];

称之为索引i+1。这32313133353236313431303231363533e78988e69d8331333431356666将导致一个index out of bounds exception。(在你n等于19的例子中:有效索引将是[0-18]。

0469e34c2441b6f76ab3481cd27ffb26.png

你的循环将从0-18开始,但是在该行中,它将会添加一个18 + 1 = 19,这是一个无效索引)在你的循环中将条件更改为:

for (int i = 0; i

确保它在添加之后不会超出界限。

dccaaf66460532061d42f373b32116f0.png

Vertex [] vertices = new Vertex[n]; int [] numbers = new int[n*2]; AdjacencyList[] all = new AdjacencyList [n+1];for (Vertex v : vertices){

System.out.println(v.value);

AdjacencyList a = new AdjacencyList(v);

for (int i = 0; i < n; i += 2)

{

if (numbers[i] == v.value){

a.connected[i] = vertices[i+1];//array index out of bounds exception:19

else { a.connected[i] = v; }

}

all[0] = a; //add the finished adjacency list to the array

}

c14d3989891afc93b1319f657d9ba3dc.png

与n = 19我可以得到一个索引超出边界错误在代码中指出的点。我不确定我哪里会出问题,因为一切都还在19的范围内。

顶点=顶点列表[1-19],数字是一个平坦的边缘数组。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值