array insert remove

BlitzMax Forums/BlitzMax Beginners Area/array insert remove

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

If you use the for x = 0 to 9 method and there are not you can get spurious values as it reads beyond the end of the array.
This the code I came up with...
Strict
Local a:Int[] = [0,1,2,3,4,6,7,8,9]

Print "Before:"
For Local b:Int = EachIn a
	Print b
Next
Print "Length : " + Len(a)
a = insertIntoIntArray( a, 5, 5 )
Print "Insert:"
For Local c:Int = EachIn a
	Print c
Next
Print "length : " + Len(a)

a = removefromintarray(a,5)
Print "Remove:"
For Local d:Int = EachIn a
	Print d
Next
Print "length : " + Len(a)


Function insertIntoIntArray:Int[](Array:Int[],index:Int,value:Int)
	Local remain:Int = (Len(array)+1) - index
	Local result:Int[Len(array)+1]
	For Local count:Int = 0 To index-1	' copy all values before insert
		result[count] = Array[count]
	Next
	result[index] = value				' insert value
	For Local count2:Int = 0 To remain-1	' copy remaining values after insert
		result[index+count2+1] = Array[index+count2]
	Next
	Return result
End Function
Function removefromintarray:Int[](array:Int[],index:Int)
    Local result:Int[Len(array)-1]
    Local remain:Int=index+1
    For Local count:Int = 0 To index-1
        result[count] = array[count]
    Next
    For Local count:Int = index+1 To Len(result)
       result[count-1] =  array[count]
    Next
    Return result
End Function

Any improvements let me know.