Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs2-19wi
project05
Commits
f6231142
Commit
f6231142
authored
6 years ago
by
Adam Blank
Browse files
Options
Download
Email Patches
Plain Diff
Update BSTDictionary.java
parent
400f284e
master
No related merge requests found
Pipeline
#6815
failed with stage
in 0 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/edu/caltech/cs2/datastructures/BSTDictionary.java
+26
-0
src/edu/caltech/cs2/datastructures/BSTDictionary.java
with
26 additions
and
0 deletions
+26
-0
src/edu/caltech/cs2/datastructures/BSTDictionary.java
View file @
f6231142
...
...
@@ -56,6 +56,32 @@ public class BSTDictionary<K extends Comparable<K>, V> implements IDictionary<K,
public
Iterator
<
K
>
iterator
()
{
return
null
;
}
@Override
public
String
toString
()
{
if
(
this
.
root
==
null
)
{
return
"{}"
;
}
StringBuilder
contents
=
new
StringBuilder
();
IQueue
<
BSTNode
<
K
,
V
>>
nodes
=
new
ArrayDeque
<>();
BSTNode
<
K
,
V
>
current
=
this
.
root
;
while
(
current
!=
null
)
{
contents
.
append
(
current
.
key
+
": "
+
current
.
value
+
", "
);
if
(
current
.
children
[
0
]
!=
null
)
{
nodes
.
enqueue
(
current
.
children
[
0
]);
}
if
(
current
.
children
[
1
]
!=
null
)
{
nodes
.
enqueue
(
current
.
children
[
1
]);
}
current
=
nodes
.
dequeue
();
}
return
"{"
+
contents
.
toString
().
substring
(
0
,
contents
.
length
()
-
2
)
+
"}"
;
}
protected
static
class
BSTNode
<
K
,
V
>
{
public
final
K
key
;
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help