Skip to content

Commit 0970e19

Browse files
authored
Fixed indent
1 parent f512f11 commit 0970e19

File tree

1 file changed

+56
-56
lines changed

1 file changed

+56
-56
lines changed

contents/tree_traversal/code/smalltalk/tree_traversal.st

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,69 @@
11
Object subclass: #Node
2-
instanceVariableNames: 'children data'
3-
classVariableNames: ''
4-
package: ''
2+
instanceVariableNames: 'children data'
3+
classVariableNames: ''
4+
package: ''
55

66
Node>>children
7-
"Children getter."
8-
^ children
7+
"Children getter."
8+
^ children
99

1010
Node>>children: newChildren
11-
"Children setter."
12-
children := newChildren.
11+
"Children setter."
12+
children := newChildren.
1313

1414
Node>>data
15-
"Data getter"
16-
^ data
15+
"Data getter"
16+
^ data
1717

1818
Node>>data: newData
19-
"Data setter"
20-
data := newData.
19+
"Data setter"
20+
data := newData.
2121

2222
Node>>dfsRecursive
23-
"Recursive depth first search."
24-
data isNil ifFalse: [
25-
Transcript show: data.
26-
Transcript cr.
27-
].
28-
children collect: [ :each | each dfsRecursive].
23+
"Recursive depth first search."
24+
data isNil ifFalse: [
25+
Transcript show: data.
26+
Transcript cr.
27+
].
28+
children collect: [ :each | each dfsRecursive].
2929

3030
Node>>dfsRecursivePostorder
31-
"Recursive depth first search (post-order)."
32-
children collect: [ :each | each dfsRecursivePostorder ].
33-
data isNil ifTrue: [ ^ self ].
34-
Transcript show: data.
35-
Transcript cr.
31+
"Recursive depth first search (post-order)."
32+
children collect: [ :each | each dfsRecursivePostorder ].
33+
data isNil ifTrue: [ ^ self ].
34+
Transcript show: data.
35+
Transcript cr.
3636

3737
Node>>dfsInOrderBinaryTree
38-
"Recursive depth first search on a binary tree in order."
39-
children size = 2 ifTrue: [
40-
(children at: 1) dfsInOrderBinaryTree.
41-
Transcript show: data.
42-
Transcript cr.
43-
(children at: 2) dfsInOrderBinaryTree.
44-
^self.
45-
].
46-
children size = 1 ifTrue: [
47-
(children at: 1) dfsInOrderBinaryTree.
48-
Transcript show: data.
49-
Transcript cr.
50-
^self.
51-
].
52-
children size = 0 ifTrue: [
53-
Transcript show: data.
54-
Transcript cr.
55-
^self.
56-
].
57-
Transcript show: 'This is not a binary tree!'.
38+
"Recursive depth first search on a binary tree in order."
39+
children size = 2 ifTrue: [
40+
(children at: 1) dfsInOrderBinaryTree.
41+
Transcript show: data.
42+
Transcript cr.
43+
(children at: 2) dfsInOrderBinaryTree.
44+
^self.
45+
].
46+
children size = 1 ifTrue: [
47+
(children at: 1) dfsInOrderBinaryTree.
48+
Transcript show: data.
5849
Transcript cr.
59-
children length
50+
^self.
51+
].
52+
children size = 0 ifTrue: [
53+
Transcript show: data.
54+
Transcript cr.
55+
^self.
56+
].
57+
Transcript show: 'This is not a binary tree!'.
58+
Transcript cr.
59+
children length
6060

6161
Node>>dfsStack
6262
"Depth-first search with a stack."
6363
| stack top |
6464
stack := Stack new.
6565
stack push: self.
66-
[stack size > 0] whileTrue: [
66+
[stack size > 0] whileTrue: [
6767
top := stack pop.
6868
Transcript show: top data.
6969
Transcript cr.
@@ -73,18 +73,18 @@ Node>>dfsStack
7373
].
7474

7575
Node>>bfs
76-
"A breadth-first tree search using queues."
77-
| queue current |
78-
queue := LinkedList with: self.
79-
[ queue size > 0 ] whileTrue: [
80-
current := queue first.
81-
queue removeFirst.
82-
Transcript show: current.
83-
Transcript cr.
84-
current children collect: [ :child |
85-
queue addLast: child
86-
].
87-
]
76+
"A breadth-first tree search using queues."
77+
| queue current |
78+
queue := LinkedList with: self.
79+
[ queue size > 0 ] whileTrue: [
80+
current := queue first.
81+
queue removeFirst.
82+
Transcript show: current.
83+
Transcript cr.
84+
current children collect: [ :child |
85+
queue addLast: child
86+
].
87+
]
8888

8989
| test |
9090
test := Node new: 1 children: { Node new: 2.

0 commit comments

Comments
 (0)