Skip to content

Commit

Permalink
fix issue#26
Browse files Browse the repository at this point in the history
  • Loading branch information
scissorsfeet committed Oct 9, 2018
1 parent f658362 commit ebeeb7e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions go/05_array/array.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ func (this *Array) Len() uint {
return this.length
}

//判断索引是否越界
func (this *Array) isIndexOutOfRange(index uint) bool {
if this.length != 0 && index > this.length {
if index >= this.length {
return true
}
return false
Expand All @@ -52,7 +53,7 @@ func (this *Array) Insert(index uint, v int) error {
if this.Len() == uint(cap(this.data)) {
return errors.New("full array")
}
if this.isIndexOutOfRange(index) {
if index != this.length && this.isIndexOutOfRange(index) {
return errors.New("out of index range")
}

Expand Down

0 comments on commit ebeeb7e

Please sign in to comment.