MeGaDeTH_91

Matrix Fill

Feb 1st, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. private static void FillMatrix(string[,] matrix, string snakeInput, int rowCount, int colCount)
  2. {
  3. Queue<string> snake = new Queue<string>();
  4.  
  5. for (int i = 0; i < snakeInput.Length; i++)
  6. {
  7. snake.Enqueue(snakeInput[i].ToString());
  8. }
  9.  
  10. int rowCounter = 1;
  11. for (int rows = rowCount - 1; rows >= 0; rows--)
  12. {
  13. int currCols = 0;
  14. if (rowCounter % 2 != 0)
  15. {
  16. currCols = colCount - 1;
  17. }
  18. else
  19. {
  20. currCols = 0;
  21. }
  22.  
  23. while (currCols >= 0 && currCols < colCount)
  24. {
  25. string currLetter = snake.Dequeue();
  26.  
  27. matrix[rows, currCols] = currLetter;
  28.  
  29. snake.Enqueue(currLetter);
  30. if (rowCounter % 2 != 0)
  31. {
  32. currCols--;
  33. }
  34. else
  35. {
  36. currCols++;
  37. }
  38. }
  39. rowCounter++;
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment