SHARE
TWEET

Untitled

a guest Jan 21st, 2020 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Baum <T extends Comparable <T>>
  2. {
  3.     public static class Knoten <T extends Comparable<T>>
  4.     {
  5.         T t;
  6.         Knoten<T> links;
  7.         Knoten<T> rechts;
  8.     }
  9.    
  10.     Knoten<T> root;
  11.    
  12.     public void insert(Knoten<T> k)
  13.     {
  14.         if(root==null) root=k;
  15.         else insert(root, k);
  16.     }
  17.    
  18.     public void insert(Knoten<T> temp, Knoten<T> k)
  19.     {
  20.         if(k.t.compareTo( temp.t)<0)
  21.         {
  22.             if(temp.links==null)temp.links=k;
  23.             else insert(temp.links, k);
  24.         }
  25.         else
  26.         {
  27.             if(temp.rechts==null)temp.rechts=k;
  28.             else insert(temp.rechts, k);
  29.         }
  30.     }
  31.    
  32.     public void print()
  33.     {
  34.         print(root);
  35.     }
  36.    
  37.     public void print(Knoten<T> k)
  38.     {
  39.         if(k.links!=null)print(k.links);
  40.         System.out.println(k.t.toString());
  41.         if(k.rechts!=null)print(k.rechts);
  42.     }
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top