Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
11 votes
Accepted

Using smart pointers to construct Binary Search Tree

Answers to your questions Am I using std::unique_ptr correctly here? Using std::move and get? Yes, you are using those correctly. Is there any way for me to make my ...
G. Sliepen's user avatar
  • 69.5k
8 votes
Accepted

AVL Tree in C++

About inheritance I would advice against using (public) inheritance of BST for AvlTree. Consider that with your code, the ...
G. Sliepen's user avatar
  • 69.5k
8 votes

Reservation app in C with linked list, BST, and CSV

This is an interactive, menu-driven program. I would expect that runtime failures would result in a return to the menu. But instead, we unceremoniously dump the user back to their shell without ...
Toby Speight's user avatar
  • 88.4k
8 votes

Reservation app in C with linked list, BST, and CSV

UX When I run the code, I see this message: loadCSV: No such file or directory The code expects me to have a file named "res.csv", but I do not. The ...
toolic's user avatar
  • 16.1k
8 votes

Implementation of a balanced binary tree

Some notes. Indentation I would strongly suggest four spaces rather than two for each level of indentation. With such minimal indentation, your code is a bit hard to follow. You may get value out of ...
Chris's user avatar
  • 5,472
7 votes
Accepted

Pet Shelter in C++

Things you would not do in real code I know you have been given some restrictions, however in code you write outside of a course you would not have these restrictions and you would do things ...
G. Sliepen's user avatar
  • 69.5k
6 votes

Avoiding memory leaks and using pointers the right way in my binary search tree implementation - C++

Given you are not using any actual C++ functionality, I’m going to think about this code as C code that uses new and delete ...
Cris Luengo's user avatar
  • 7,031
6 votes
Accepted

Reservation app in C with linked list, BST, and CSV

General linked list suggestions You are treating Node ** as (the head or tail of) a list. This means that insertion at the opposite end must traverse the entire ...
Chris's user avatar
  • 5,472
5 votes
Accepted

Binary Search Tree implementation in C [1]

Fix compilation warnings If your compiler isn't telling you about these, you haven't enabled enough warnings: BST* create_bst(void) { /*🔺🔺🔺*/ <...
Toby Speight's user avatar
  • 88.4k
4 votes
Accepted

BST implementation in rust

This looks good for a first project. Most of the review to follow ranges from debatable to nitpicky. Representation It's unusual that BST can't represent an empty ...
trent's user avatar
  • 1,124
4 votes

red black tree implementation in cpp

This ia a great follow-up and deserves a closer look than I can give it right now, but a handful of things jumped out at me. Write the Class as a Template You’ve got a nice tree class, but it’d be a ...
Davislor's user avatar
  • 9,165
4 votes
Accepted

Binary Search Tree - My own version of delete function

Address more fundamental issues before worrying about delete A BST should be able to hold false values. For example, zero. Instead of if not self.root, use ...
FMc's user avatar
  • 13.1k
4 votes
Accepted

Sort array of numbers using tree sort - Leetcode 912

edge case I feel the first result displayed here is reasonable: >>> sorted([]) [] >>> sorted([6, 4]) [4, 6] Given zero elements, and asked to ...
J_H's user avatar
  • 42.7k
4 votes

Reservation app in C with linked list, BST, and CSV

The recursive call in printListRecursive() is not needed, and could be a simple while loop: ...
silver drake's user avatar
3 votes
Accepted

Maximum Depth of Binary Tree in JavaScript

A few minor style suggestions for starters: Use const instead of let. let says "I'm ...
ggorlen's user avatar
  • 4,197
3 votes
Accepted

Binary Search Tree in C++ without parent pointers

Move struct Node inside struct BST A Node is just an implementation detail of a ...
G. Sliepen's user avatar
  • 69.5k
3 votes
Accepted

Binary Search Tree implementation in C++ with templates

Stick with a single language I see you have some Catalan comments, and instead of BSTTree you write BSTArbre, but all other ...
G. Sliepen's user avatar
  • 69.5k
3 votes

Simple non balancing indexed binary search tree

More horizontal spacing please. Give your operators some breathing space. It is very hard to read things like root==nullptr||i<0||i>=root->size. BTW, I ...
vnp's user avatar
  • 58.7k
3 votes

Simple non balancing indexed binary search tree

Use unique_ptr for root, left, and right Because each ...
frozenca's user avatar
  • 1,751
3 votes

Finding inorder successor of a BST in C

Missing return Code may even fail the last rt == INT_MAX and then no return is specified. ...
chux's user avatar
  • 36.5k
3 votes

Validate Search Binary Tree

To validate a BST tree you need to validate a sub tree is between two values. Remember that all nodes to the left must be less than the current node and everything to the right is larger. So after a ...
Loki Astari's user avatar
  • 97.7k
3 votes
Accepted

BST implementation using smart pointers in C++

This is too long for me to review thoroughly, but on a cursory glance (I'll just go go top to bottom): #include <iostream> is unneeded There is no point in ...
vvotan's user avatar
  • 806
3 votes

Avoiding memory leaks and using pointers the right way in my binary search tree implementation - C++

For C++, avoid using new/delete or c variants of memory allocation. Instead use std::make_unique. Fix formatting, for example, consider using ...
oleksii's user avatar
  • 163
3 votes

Maximum Sum BST in a Binary Tree

Is there anything I can change, in the same given code, that would optimize it and/or get it accepted? Your “Time Limit Exceeded” question is basically asking “when is this code slow?” We tend to ...
J_H's user avatar
  • 42.7k
3 votes

Maximum Sum BST in a Binary Tree

Beyond method naming and a comment stating what the signature boolean isBST(TreeNode root,…) suggest, the code gives no indication what it is there for, what the ...
greybeard's user avatar
  • 7,779
3 votes

Weight balanced tree in OCaml

From a reviewer perspective I find it difficult to identify what the short variable and type names mean and thus for what they are used. Note: I must admit that I am not familiar with the language ...
Thibe's user avatar
  • 401
3 votes

Implementation of a balanced binary tree

Implement the interface of std::map To make your code be a drop-in replacement for standard library containers, try to implement the same interface for your ...
G. Sliepen's user avatar
  • 69.5k
2 votes

Implementing a binary search tree using std::unique_ptr

Observation I normally don't see a parent pointer in a binary tree. Because you have to keep and maintain this extra pointer your code is a lot more complicated ...
Loki Astari's user avatar
  • 97.7k

Only top scored, non community-wiki answers of a minimum length are eligible