File tree 1 file changed +6
-2
lines changed
1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -12,36 +12,40 @@ func spiralTraverse(m [][]string) {
12
12
row := 0
13
13
column := 0
14
14
for visited < rowSize * columnSize {
15
- fmt .Printf ("%s\n " , m [row ][column ])
15
+ fmt .Printf ("%s " , m [row ][column ])
16
16
visited ++
17
- switch dir % 4 {
17
+ switch dir % 4 {
18
18
case 0 : //Top path
19
19
if column < rowSize - row - 1 {
20
20
column ++ //Go right
21
21
} else {
22
22
row ++ //Turn down
23
23
dir ++
24
+ fmt .Println ()
24
25
}
25
26
case 1 : //Right path
26
27
if row < column {
27
28
row ++ //Go down
28
29
} else {
29
30
column -- //Turn left
30
31
dir ++
32
+ fmt .Println ()
31
33
}
32
34
case 2 : //Bottom path
33
35
if column > rowSize - row - 1 {
34
36
column -- //Go left
35
37
} else {
36
38
row -- //Turn up
37
39
dir ++
40
+ fmt .Println ()
38
41
}
39
42
case 3 : //Left path
40
43
if row > column + 1 {
41
44
row -- //Go up
42
45
} else {
43
46
column ++ //Turn right
44
47
dir ++
48
+ fmt .Println ()
45
49
}
46
50
}
47
51
}
You can’t perform that action at this time.
0 commit comments