Tree Data Structure in Java

Asked 2 years ago, Updated 2 years ago, 130 views

Is there a good data structure that is tree in Java? All I need is

Can I make something like this?

java date-structures tree

2022-09-22 22:30

1 Answers

public class Tree<T> {
    private Node<T> root;

    public Tree(T rootData) {
        root = new Node<T>();
        root.data = rootData;
        root.children = new ArrayList<Node<T>>();
    }

    public static class Node<T> {
        private T data;
        private Node<T> parent;
        private List<Node<T>> children;
    }
}

This is a basic tree structure that can be used as a String or other object. You can easily modify it in any other form you want. You just need to add things like insert, delete, and modify. Node is the default unit of the tree.


2022-09-22 22:30

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.