Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introducing binary search tree implementation #15

Merged
merged 7 commits into from
Jan 3, 2025

Conversation

spirosmaggioros
Copy link
Contributor

Implemented a binary serach tree in zig:

Methods:

  • Implemented methods for inserting (insert), removing (remove), and searching (search) elements in the tree.
  • Added traversal methods for inorder (inorder), preorder (preorder), and postorder (postorder) traversals.
  • Included a destroy method to deallocate memory used by the tree.

Also, the PR includes the unit tests for the container.

@kassane
Copy link
Member

kassane commented Jan 2, 2025

Hi @spirosmaggioros,

Thanks for your contribution and happy new year!!

What is the difference compared to the previous implementation?

https://github.com/TheAlgorithms/Zig/blob/main/search%2FbinarySearchTree.zig

@spirosmaggioros
Copy link
Contributor Author

Happy new year to you too!

Actually i want to contribute a lot and i started by trying fixing the already implemented data structures.
My implementation has more methods(the ones that we both have are the same) and also they are more user friendly. Feels more like a class(accepts T key instead of nodes), thus, having an allocator as well.

I can try and merge my additions into the already implemented file if you wish.

Thanks.
Spiros.

@kassane
Copy link
Member

kassane commented Jan 2, 2025

I can try and merge my additions into the already implemented file if you wish.

Please, it would help a lot, avoiding redundancies.

Now the new BST function has more methods and in general feels more like my previous DoublyLinkedList implementation.
@spirosmaggioros
Copy link
Contributor Author

Just commited this. I updated the BinarySearchTree.zig with the new implementation instead of creating one at dataStructures.

@kassane Do i have to add this to build.zig and runall.sh?

@kassane
Copy link
Member

kassane commented Jan 3, 2025

Do i have to add this to build.zig and runall.sh?

Again?

Zig/build.zig

Lines 47 to 53 in e68f833

if (std.mem.eql(u8, op, "search/bSearchTree"))
build_algorithm(b, .{
.optimize = optimize,
.target = target,
.name = "binarySearchTree.zig",
.category = "search",
});

Zig/runall.cmd

Line 34 in e68f833

%ZIG_TEST% -Dalgorithm=search/bSearchTree %Args%

Zig/runall.sh

Line 34 in e68f833

$ZIG_TEST -Dalgorithm=search/bSearchTree $Args

rebase and add doublyLinkedList

@spirosmaggioros
Copy link
Contributor Author

spirosmaggioros commented Jan 3, 2025

Do i have to add this to build.zig and runall.sh?

Again?

Zig/build.zig

Lines 47 to 53 in e68f833

if (std.mem.eql(u8, op, "search/bSearchTree"))
build_algorithm(b, .{
.optimize = optimize,
.target = target,
.name = "binarySearchTree.zig",
.category = "search",
});

Zig/runall.cmd

Line 34 in e68f833

%ZIG_TEST% -Dalgorithm=search/bSearchTree %Args%

Zig/runall.sh

Line 34 in e68f833

$ZIG_TEST -Dalgorithm=search/bSearchTree $Args

rebase and add doublyLinkedList

Sorry, i forgot it exists.
Will add the following in every new PR from now on.

search/binarySearchTree.zig Outdated Show resolved Hide resolved
@kassane kassane merged commit 3e0eec6 into TheAlgorithms:main Jan 3, 2025
5 checks passed
@kassane
Copy link
Member

kassane commented Jan 3, 2025

Awesome contributions, @spirosmaggioros

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants