Binary tree- SQL to Java representation -
i have tree data structure representation in sql , want display data, correct relations of each node in java can search algorithm on them.
so,i thought using left , right columns may transform general tree binary tree more easier apply more search algoritms on them.
also, want able make different operations add/remove root, nodes ,leafs.

i newbie in programming here classes
public class node { private int id; private string name; private int leftid; private int rightid; private int deepth; public int getid() { return id; } public void setid(int id) { this.id = id; } public string getname() { return name; } public void setname(string name) { this.name = name; } public int getleftid() { return leftid; } public void setleftid(int leftid) { this.leftid = leftid; } public int getrightid() { return rightid; } public void setrightid(int rightid) { this.rightid = rightid; } public int getdeepth() { return deepth; } public void setdeepth(int deepth) { this.deepth = deepth; }//con statement list<node> nodes = new arraylist<>(); while(rs.next()) {node nodes = new node(); nodes.setname( rs.getstring("name")); //other nodes.add(nodes); } return nodes; } public class tree{ //here need }
i tried assign values database coresponding left , right. don't succed. reason? beacuse don't know assing root , leaf. know if use values can (code binary tree inserting values keyboard)
<!-- language: java--> class treenode<e> { protected e element; protected treenode<e> left; protected treenode<e> right; public treenode(e e) { element = e; } }// create root node treenode<integer> root = new treenode<>(60); // create left child node root.left = new treenode<>(55); // create right child node root.right = new treenode<>(100); -but don't know how db in lists , assign them can use them @sasha salauyou trying transform ordinary tree db binary tree in java
Comments
Post a Comment