Skip to content

Instantly share code, notes, and snippets.

View msuganthan's full-sized avatar
🎯
Focusing

Suganthan Madhavan msuganthan

🎯
Focusing
View GitHub Profile
@msuganthan
msuganthan / Rust.md
Last active February 23, 2025 16:30
Rust notes

Ownership

  • Set of rules that govern memory management
  • Rules are enforced at compile time
  • Any violation would result in compile time error.

Three rules

  • Each value in Rust has an owner
  • There can only be one owner at a time
static class BTreePrinter {
public static <T extends Comparable<?>> void printNode(Node root) {
int maxLevel = BTreePrinter.maxLevel(root);
printNodeInternal(Collections.singletonList(root), 1, maxLevel);
}
private static <T extends Comparable<?>> void printNodeInternal(List<Node> nodes, int level, int maxLevel) {
if (nodes.isEmpty() || BTreePrinter.isAllElementsNull(nodes))