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.

using slices ( cant think how to copy from x to y and retian the prevision values )
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)) - index
	Local result:Int[]
	result = array[..index]
	result = result[..(Len(array)+1)]
	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[]
    Local remain:Int=index+1
    result = array[..index]
	result = result[..(Len(array)-1)]
    For Local count:Int = index+1 To Len(result)
       result[count-1] =  array[count]
    Next
    Return result
End Function