Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Node insert(Node root, int data) {
- Node inserter = new Node(data);
- Node temp = root;
- while (true) {
- if (inserter.data <= temp.data) {
- if (temp.left == null) {
- temp.left = inserter;
- break;
- } else
- temp = temp.left;
- } else {
- if (temp.right == null) {
- temp.right = inserter;
- break;
- } else
- temp = temp.right;
- }
- }
- return root;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement