fix(算法): 符号表——二分查找实现有序符号表中插入新节点考虑容量问题

This commit is contained in:
Mingyue Li 2021-11-16 10:20:49 +08:00 committed by GitHub
parent 456ff183d5
commit ec84f5b3ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -213,6 +213,8 @@ public class BinarySearchOrderedST<Key extends Comparable<Key>, Value> implement
values[index] = value;
return;
}
// 如果插入后容量大于初始化容量则放弃当前操作或者其他实现
if (N >= keys.length) return;
// 否则在数组中插入新的节点需要先将插入位置之后的元素都向后移动一个位置
for (int j = N; j > index; j--) {
keys[j] = keys[j - 1];