1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-04-15 05:22:12 +02:00

Slightly simplify binary tree exercise (#2002)

Give students a little more context for the binary tree exercise by
giving them the wrapper methods on `BinaryTree` at the start and
explicitly asking them to implement the methods on `Subtree`. I think
this simplifies the exercise a bit and makes it a bit more focused for
students.
This commit is contained in:
Nicole L 2024-04-18 11:50:27 -07:00 committed by GitHub
parent e6021ce5d0
commit c9e08fae60
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 3 deletions

View File

@ -14,10 +14,10 @@ Implement the following types, so that the given tests pass.
Extra Credit: implement an iterator over a binary tree that returns the values
in order.
```rust,editable
```rust,editable,ignore
{{#include exercise.rs:types}}
// Implement `new`, `insert`, `len`, and `has`.
// Implement `new`, `insert`, `len`, and `has` for `Subtree`.
{{#include exercise.rs:tests}}
```

View File

@ -35,7 +35,6 @@ struct Subtree<T: Ord>(Option<Box<Node<T>>>);
pub struct BinaryTree<T: Ord> {
root: Subtree<T>,
}
// ANCHOR_END: types
impl<T: Ord> BinaryTree<T> {
fn new() -> Self {
@ -54,6 +53,7 @@ impl<T: Ord> BinaryTree<T> {
self.root.len()
}
}
// ANCHOR_END: types
impl<T: Ord> Subtree<T> {
fn new() -> Self {