Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #define RIGHT 1
- #define LEFT 2
- #define UP 3
- #define DOWN 4
- int *snail(size_t *outsz, int **mx, size_t m, size_t n) {
- int i = 0, j = 0, num = 0, movement = RIGHT, multiply_n = n*n, left_slide = -1;
- int *returned_array = (int *)malloc(sizeof(int) * multiply_n);
- for(int num = 0; num < multiply_n; num++){
- returned_array[num] = mx[j][i];
- if(i+1 == n && movement == RIGHT) {
- movement = DOWN;
- left_slide++;
- }else if(j+1 == n && movement == DOWN) {
- movement = LEFT;
- }else if((i == 0 && movement == LEFT) || (left_slide == i && movement == LEFT)) {
- movement = UP;
- n--;
- }else if(j == m-n && movement == UP) {
- movement = RIGHT;
- }
- if(movement == RIGHT) i++;
- else if(movement == DOWN) j++;
- else if(movement == LEFT) i--;
- else j--;
- //printf("%d %d %d %s %d\n", i, j, n, to_string_movement(movement), cube[j][i]);
- }
- *outsz = multiply_n;
- return returned_array;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement