Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Baum <T extends Comparable <T>>
- {
- public static class Knoten <T extends Comparable<T>>
- {
- T t;
- Knoten<T> links;
- Knoten<T> rechts;
- }
- Knoten<T> root;
- public void insert(Knoten<T> k)
- {
- if(root==null) root=k;
- else insert(root, k);
- }
- public void insert(Knoten<T> temp, Knoten<T> k)
- {
- if(k.t.compareTo( temp.t)<0)
- {
- if(temp.links==null)temp.links=k;
- else insert(temp.links, k);
- }
- else
- {
- if(temp.rechts==null)temp.rechts=k;
- else insert(temp.rechts, k);
- }
- }
- public void print()
- {
- print(root);
- }
- public void print(Knoten<T> k)
- {
- if(k.links!=null)print(k.links);
- System.out.println(k.t.toString());
- if(k.rechts!=null)print(k.rechts);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement