wheelsmanx

temp

Feb 7th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. // Given a matrix of M x N elements, return all elements of the matrix in spiral order.
  2.  
  3. // Input: [
  4. // [1, 2, 3],
  5. // [4, 5, 6],
  6. // [7, 8, 9]
  7. // ]
  8.  
  9. // Output: [1, 2, 3, 6, 9, 8, 7, 4, 5]
  10.  
  11. // Input: [
  12. // [1, 2, 3, 4],
  13. // [5, 6, 7, 8],
  14. // [9, 10, 11, 12]
  15. // ]
  16. // Output: [1, 2, 3, 4, 8, 12, 11, 10, 9, 5, 6, 7]
  17. #include <iostream>
  18. #include <vector>
  19. using namespace std;
  20.  
  21. void calculateVector(vector<vector<int>> functionInput) {
  22. int x = 0, y = 0;
  23. char direction = 'e';
  24. int numberOfSteps = 0;
  25. int stepsTaken = 0;
  26. /*for(auto elementA: functionInput){
  27. numberOfSteps = elementA.size();
  28. for(auto elementB : elementA){
  29. switch(direction){
  30. case 'e': {
  31. //subtract at direction change to south
  32. if(numberOfSteps == stepsTaken){
  33. direction = 's';
  34. x++;
  35. stepsTaken = 0;
  36. numberOfSteps--;
  37.  
  38. }else{
  39. stepsTaken++;
  40. cout << functionInput[x][y] << endl;
  41. }
  42. }
  43. case 's': {
  44. if(numberOfSteps == stepsTaken){
  45. direction = 'w';
  46. y++;
  47. stepsTaken = 0;
  48. }else{
  49. stepsTaken++;
  50. cout << functionInput[x][y] << endl;
  51. }
  52.  
  53. }
  54. case 'w': {
  55. //subtract at direction change to north
  56. if(numberOfSteps == stepsTaken){
  57. direction = 'n';
  58. x--;
  59. stepsTaken = 0;
  60. numberOfSteps--;
  61. }else{
  62. stepsTaken++;
  63. cout << functionInput[x][y] << endl;
  64. }
  65.  
  66. }
  67. case 'n': {
  68. if(numberOfSteps == stepsTaken){
  69. direction = 'e';
  70. y--;
  71. stepsTaken = 0;
  72. }else{
  73. stepsTaken++;
  74. cout << functionInput[x][y] << endl;
  75. }
  76.  
  77. }
  78.  
  79. }
  80. }
  81. */
  82. }
  83. }
  84.  
  85.  
  86.  
  87.  
  88. int main() {
  89. vector<int> tempVectorOfInts;
  90. vector<vector<int>> vectorHolder;
  91. tempVectorOfInts.push_back(1);
  92. tempVectorOfInts.push_back(2);
  93. tempVectorOfInts.push_back(3);
  94. vectorHolder.push_back(tempVectorOfInts);
  95. tempVectorOfInts.erase(tempVectorOfInts.begin(), tempVectorOfInts.end());
  96. tempVectorOfInts.push_back(4);
  97. tempVectorOfInts.push_back(5);
  98. tempVectorOfInts.push_back(6);
  99. vectorHolder.push_back(tempVectorOfInts);
  100. tempVectorOfInts.erase(tempVectorOfInts.begin(), tempVectorOfInts.end());
  101. tempVectorOfInts.push_back(7);
  102. tempVectorOfInts.push_back(8);
  103. tempVectorOfInts.push_back(9);
  104. vectorHolder.push_back(tempVectorOfInts);
  105. tempVectorOfInts.erase(tempVectorOfInts.begin(), tempVectorOfInts.end());
  106. calculateVector(vectorHolder);
  107.  
  108.  
  109. return 0;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment