Advertisement
xladomaz

Untitled

Mar 9th, 2020
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #include <stdlib.h>
  2.  
  3. #define RIGHT 1
  4. #define LEFT 2
  5. #define UP 3
  6. #define DOWN 4
  7.  
  8. int *snail(size_t *outsz, int **mx, size_t m, size_t n) {
  9. int i = 0, j = 0, num = 0, movement = RIGHT, multiply_n = n*n, left_slide = -1;
  10. int *returned_array = (int *)malloc(sizeof(int) * multiply_n);
  11.  
  12. for(int num = 0; num < multiply_n; num++){
  13.  
  14. returned_array[num] = mx[j][i];
  15.  
  16. if(i+1 == n && movement == RIGHT) {
  17. movement = DOWN;
  18. left_slide++;
  19. }else if(j+1 == n && movement == DOWN) {
  20. movement = LEFT;
  21. }else if((i == 0 && movement == LEFT) || (left_slide == i && movement == LEFT)) {
  22. movement = UP;
  23. n--;
  24. }else if(j == m-n && movement == UP) {
  25. movement = RIGHT;
  26. }
  27. if(movement == RIGHT) i++;
  28. else if(movement == DOWN) j++;
  29. else if(movement == LEFT) i--;
  30. else j--;
  31. //printf("%d %d %d %s %d\n", i, j, n, to_string_movement(movement), cube[j][i]);
  32. }
  33. *outsz = multiply_n;
  34. return returned_array;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement