Language: Java
BinaryTree.java
public class BinaryTree { private BinaryTree start, left, right; private int data; public BinaryTree () { while(true)break; //Do nothing. } private BinaryTree ( int d ) { data = d; } public void insert ( int d ) { if ( start == null ) { start = this; start.data = d; System.out.println ("Inserted "+d); return; } insert ( start, d ); } private BinaryTree insert ( BinaryTree b, int d ) { if ( b == null ){ System.out.println ("Inserted "+d); return new BinaryTree ( d ); } else if ( d > b.data ) { if ( b.right == null )b.right = insert ( b.right, d ); else insert ( b.right, d ); return null; } else if ( d < b.data ) { if ( b.left == null )b.left = insert ( b.left, d ); else insert ( b.left, d ); return null; } else return null; } public void inOrder () { inOrder ( start ); } private void inOrder ( BinaryTree b ) { if ( b == null ) return; inOrder ( b.left ); System.out.println ( b.data ); inOrder ( b.right ); } }
Tags:
Description:
Use it, but don't be a smart ass. You are hereby not allowed to make any commercial usage of this data structure without prior written, signed and verified permission of the author, that's me.
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

