Advertisement
Guest User

Untitled

a guest
Dec 19th, 2014
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. int rows = (array.Length + cols - 1) / cols; //ceiling function to determine rows needed
  2. int pos = array.Length - cols; //starting position in index transfer
  3. int offset = 0; //needed when negative index reached
  4. for (int i = 0; i < rows; i++)
  5. {
  6. for (int j = 0; j < cols; j++)
  7. {
  8. if (pos + j >= 0)
  9. array[cols * i + j - offset] = temp[pos + j]; //assign values of temp to array
  10. else
  11. ++offset; //takes care of negative indeces
  12. }
  13. pos -= cols;
  14. }
  15.  
  16. return array;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement