I have an initial array of Tiles ordered by [row,col] like this
[0,1] [0,2] [0,3]
[1,1] [1,2] [1,3]
i need to binary insert elements ordered by row and colum like this
binaryInsert([0,0])
binaryInsert([1,0])
and the expected result will be an array ordered like this
[0,0] [0,1] [0,2] [0,3]
[1,0] [1,1] [1,2] [1,3]
basically i need to be able to add rows and columns in every direction (top,right,left,down) but always ordered like the example below.
I can transform rows and cols to one value with this function
function coordToOrder(row,col,numCols){
return col+initCols*row
}
var initCols = 5;
var order = coordToOrder(1,4,initCols);
alert(order)
but then if i need to insert a tile at order 10 and is already inserted i need to increment the following.
I'm tryng to use a binary solution instead the sort function because is faster.
Thanks for your help!