Skip to content

Commit 6bb9c12

Browse files
committed
1 parent 028dc10 commit 6bb9c12

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

data-structures/matrix/matrix.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,40 @@ func spiralTraverse(m [][]string) {
1212
row := 0
1313
column := 0
1414
for visited < rowSize * columnSize {
15-
fmt.Printf("%s\n", m[row][column])
15+
fmt.Printf("%s ", m[row][column])
1616
visited++
17-
switch dir%4 {
17+
switch dir % 4 {
1818
case 0: //Top path
1919
if column < rowSize - row - 1 {
2020
column++ //Go right
2121
} else {
2222
row++ //Turn down
2323
dir++
24+
fmt.Println()
2425
}
2526
case 1: //Right path
2627
if row < column {
2728
row++ //Go down
2829
} else {
2930
column-- //Turn left
3031
dir++
32+
fmt.Println()
3133
}
3234
case 2: //Bottom path
3335
if column > rowSize - row - 1 {
3436
column-- //Go left
3537
} else {
3638
row-- //Turn up
3739
dir++
40+
fmt.Println()
3841
}
3942
case 3: //Left path
4043
if row > column + 1 {
4144
row-- //Go up
4245
} else {
4346
column++ //Turn right
4447
dir++
48+
fmt.Println()
4549
}
4650
}
4751
}

0 commit comments

Comments
 (0)