Disclaimer: Dieser Thread wurde aus dem alten Forum importiert. Daher werden eventuell nicht alle Formatierungen richtig angezeigt. Der ursprüngliche Thread beginnt im zweiten Post dieses Threads.
12.6 Fancy Tree
Wie viele Schlüssel darf dann die Wurzel enthalten? Unbeschränkt?
Mindestens 1 und maximal 2g.
Hier hab ich z.B. Code der einen ausgeglichenen Baum erzeugen sollte. Also einfach die aktuellen Tests aus der main-Methode auskommentieren und duch diesen hier ersetzen.
FancyTree<Integer> fancyTree = new FancyTree<Integer>(2);
fancyTree.insertKeyInTree(5);
fancyTree.insertKeyInTree(10);
fancyTree.insertKeyInTree(15);
fancyTree.insertKeyInTree(20);
fancyTree.insertKeyInTree(25);
fancyTree.insertKeyInTree(30);
fancyTree.insertKeyInTree(35);
fancyTree.insertKeyInTree(38);
fancyTree.insertKeyInTree(45);
fancyTree.insertKeyInTree(50);
fancyTree.insertKeyInTree(55);
fancyTree.insertKeyInTree(60);
fancyTree.insertKeyInTree(65);
fancyTree.insertKeyInTree(70);
fancyTree.insertKeyInTree(75);
fancyTree.insertKeyInTree(80);
fancyTree.insertKeyInTree(85);
fancyTree.insertKeyInTree(90);
fancyTree.insertKeyInTree(95);
fancyTree.insertKeyInTree(100);
fancyTree.insertKeyInTree(105);
fancyTree.insertKeyInTree(110);
fancyTree.insertKeyInTree(115);
fancyTree.insertKeyInTree(120);
fancyTree.insertKeyInTree(125);
fancyTree.insertKeyInTree(130);
fancyTree.insertKeyInTree(135);
fancyTree.insertKeyInTree(140);
fancyTree.insertKeyInTree(145);
fancyTree.insertKeyInTree(150);
fancyTree.insertKeyInTree(155);
fancyTree.insertKeyInTree(160);
fancyTree.insertKeyInTree(36);
fancyTree.insertKeyInTree(37);
fancyTree.insertKeyInTree(165);
fancyTree.insertKeyInTree(170);
fancyTree.insertKeyInTree(175);
fancyTree.insertKeyInTree(180);
fancyTree.insertKeyInTree(185);
fancyTree.insertKeyInTree(190);
fancyTree.insertKeyInTree(195);
fancyTree.insertKeyInTree(200);
fancyTree.insertKeyInTree(205);
fancyTree.insertKeyInTree(210);
fancyTree.insertKeyInTree(215);
fancyTree.insertKeyInTree(220);
fancyTree.insertKeyInTree(225);
fancyTree.insertKeyInTree(230);
fancyTree.insertKeyInTree(235);
fancyTree.insertKeyInTree(240);
fancyTree.insertKeyInTree(245);
fancyTree.insertKeyInTree(2);
fancyTree.insertKeyInTree(3);
fancyTree.insertKeyInTree(7);
fancyTree.insertKeyInTree(18);
fancyTree.insertKeyInTree(19);
fancyTree.insertKeyInTree(21);
fancyTree.insertKeyInTree(23);
fancyTree.insertKeyInTree(27);
fancyTree.insertKeyInTree(187);
fancyTree.insertKeyInTree(193);
fancyTree.insertKeyInTree(1);
fancyTree.insertKeyInTree(4);
fancyTree.insertKeyInTree(6);
fancyTree.insertKeyInTree(8);
fancyTree.insertKeyInTree(201);
fancyTree.insertKeyInTree(203);
fancyTree.insertKeyInTree(16);
fancyTree.insertKeyInTree(17);
fancyTree.insertKeyInTree(48);
fancyTree.insertKeyInTree(49);
fancyTree.insertKeyInTree(54);
fancyTree.insertKeyInTree(46);
fancyTree.insertKeyInTree(143);
fancyTree.insertKeyInTree(147);
fancyTree.insertKeyInTree(96);
fancyTree.insertKeyInTree(218);
fancyTree.insertKeyInTree(222);
fancyTree.insertKeyInTree(101);
fancyTree.insertKeyInTree(102);
fancyTree.insertKeyInTree(107);
fancyTree.insertKeyInTree(106);
fancyTree.insertKeyInTree(111);
fancyTree.insertKeyInTree(47);
fancyTree.insertKeyInTree(52);
fancyTree.insertKeyInTree(53);
fancyTree.insertKeyInTree(81);
fancyTree.insertKeyInTree(88);
fancyTree.insertKeyInTree(89);
fancyTree.insertKeyInTree(73);
fancyTree.insertKeyInTree(74);
fancyTree.insertKeyInTree(87);
fancyTree.insertKeyInTree(86);
fancyTree.insertKeyInTree(82);
fancyTree.insertKeyInTree(83);
fancyTree.insertKeyInTree(151);
fancyTree.insertKeyInTree(152);
fancyTree.insertKeyInTree(156);
fancyTree.insertKeyInTree(153);
fancyTree.insertKeyInTree(154);
fancyTree.insertKeyInTree(157);
fancyTree.insertKeyInTree(161);
fancyTree.insertKeyInTree(162);
fancyTree.insertKeyInTree(163);
fancyTree.insertKeyInTree(164);
fancyTree.insertKeyInTree(158);
fancyTree.insertKeyInTree(159);
fancyTree.insertKeyInTree(173);
fancyTree.insertKeyInTree(177);
fancyTree.insertKeyInTree(97);
fancyTree.insertKeyInTree(98);
fancyTree.insertKeyInTree(103);
fancyTree.insertKeyInTree(104);
fancyTree.insertKeyInTree(108);
fancyTree.insertKeyInTree(109);
fancyTree.insertKeyInTree(113);
fancyTree.insertKeyInTree(117);
fancyTree.insertKeyInTree(127);
fancyTree.insertKeyInTree(129);
fancyTree.insertKeyInTree(250);
fancyTree.insertKeyInTree(233);
fancyTree.insertKeyInTree(237);
fancyTree.insertKeyInTree(333);
fancyTree.insertKeyInTree(337);
fancyTree.printTree();
--> 45 90 135 180
--> 5 15 20 30
--> 1 2 3 4
--> 6 7 8 10
--> 16 17 18 19
--> 21 23 25 27
--> 35 36 37 38
--> 50 60 75 85
--> 46 47 48 49
--> 52 53 54 55
--> 65 70 73 74
--> 80 81 82 83
--> 86 87 88 89
--> 100 105 110 120
--> 95 96 97 98
--> 101 102 103 104
--> 106 107 108 109
--> 111 113 115 117
--> 125 127 129 130
--> 150 155 160 165
--> 140 143 145 147
--> 151 152 153 154
--> 156 157 158 159
--> 161 162 163 164
--> 170 173 175 177
--> 195 210 225 240
--> 185 187 190 193
--> 200 201 203 205
--> 215 218 220 222
--> 230 233 235 237
--> 245 250 333 337
D.h. durch das Hinzufügen eines weiteren Elements sollte eine neue Wurzel entstehen
Das ist eigentlich ne nette Klausuraufgabe. Wenig Code aber ordentlich Denksport.
Hallo, der unter zwischen die Methoden isKeyInTree(T key) und isKeyInNode(T key) ist mir nicht klar
Hallo, der unter zwischen die Methoden isKeyInTree(T key) und isKeyInNode(T key) ist mir nicht klar
isKeyInNode() macht die eigentliche (rekursive) Arbeit fuer einen einzelnen Knoten im Baum, da ist also die eigentliche Suche implementiert. isKeyInTree() hingegen ist letztendlich nur ein Wrapper, der vom Benutzer der Datenstruktur von außen aufgerufen wird, und der die Arbeit an einen Aufruf von isKeyInNode() fuer den Wurzel-Knoten weiterreicht.
hat sich erledigt