Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int rows = (array.Length + cols - 1) / cols; //ceiling function to determine rows needed
- int pos = array.Length - cols; //starting position in index transfer
- int offset = 0; //needed when negative index reached
- for (int i = 0; i < rows; i++)
- {
- for (int j = 0; j < cols; j++)
- {
- if (pos + j >= 0)
- array[cols * i + j - offset] = temp[pos + j]; //assign values of temp to array
- else
- ++offset; //takes care of negative indeces
- }
- pos -= cols;
- }
- return array;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement