Im Versuch, ein Array basiert zu bauen, „Binary Search Tree“ von nach dem Algorithmus an:
... mit dem Algorithmus I mit dem folgenden Code kam:
void BST::insert( const data &aData )
{
item *y = &items[root_index]; // Algorithm calls for NULL assignment..
item *x = &items[root_index];
while ( ! items[root_index].empty )
{
y->theData = x->theData; // Ptrs are required or else a crash occurs.
if ( aData < x->theData )
{
x->leftChild = aData;
}
else
{
x->rightChild = items[root_index].theData;
}
// what is p[z] = y? is it outside the looping scheme?
root_index++; // and make the new child the root?
}
if ( y->empty )
{
items[root_index].theData = aData;
items[root_index].empty = false;
}
else if ( aData < y->theData )
{
y->leftChild = aData;
// If we already have a left/right child...make it the root? re-cmpr?
}
else
{
y->rightChild = items[root_index].theData;
}
}
Fragen:
Ich kann nicht herausfinden, was p [z] <- y Mittel .... Im nur die Wurzel des Zunehmen eine Traverse zu imitieren.
Wenn ich schon ein linkes / rechtes Kind haben, dann sollte ich das linke / rechte Kind machen taht im über die Wurzel zu überschreiben? Darin sollte ich es machen recurisve so wird es auf die ursprüngliche Wurzel zurückzuschalten, „R“?
Einfügungen einzufügen ( R); Einfügen ( A); insert ( F); Einfügen ( L); Einfügen ( B); Einfügen ( C); insert ( T);













