While experimenting with Rust I’d like to see Rc and RefCell in action to better understand how smart pointers in Rust work. In this post I implement binary search tree in Rust using only Rc and RefCell.

Basically, Binary Search Tree is a binary tree data structure with the following properties

  • given a node and its key k, any key in the node’s left subtree is less than k
  • given a node and its key k, any key in the node’s right subtree is greater than k

Let’s get started by creating a new project cargo new bstree

Create a new folder src/bs_tree and inside bs_tree folder create a file node.rs which will contain implementation for a single node

#algorithms #rustlang #binary-tree #rust #data-structures

Implementation of Binary Search Tree in Rust
18.85 GEEK