Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Binary Tree insert => Problem

Empfohlene Antworten

Hallo zusammen,

ich entwickle mit Bloodshed Dev-Cpp 4.9.9.2 und habe Sorgen mit dem Code hier...

Problem: Ich kann die Wurzel konstruieren, insert von 1 und 19 funktioniert tadellos, aber alles weitere wird dann an die position von 19 geschrieben. er merkt sich die adresse irgendwie nicht ?!?

Das muss am Gültigkeitsbereich von irgendwelchen Variablen liegen. Problem hierbei ist dass ich seit Tagen dran sitze und es nicht finde. Ist auch schwer zu debuggen so...

Vielleicht kann mir hier jemand sagen wo der Fehler liegt, ich würde mich echt freuen wenn ich Hilfe finde.

ciao,

Soke2k

Hier der Code:

#define TNULL (BinaryTreeNode*) NULL

class BinaryTreeNode{

private:

int content; // Inhalt

BinaryTreeNode *l_next; // left successor

BinaryTreeNode *r_next; // right successor

BinaryTreeNode *_insertNode(BinaryTreeNode *btn, int content)

{

if(btn == TNULL)

{

return new BinaryTreeNode(content);

}

if(content < btn->content)

{

btn->l_next = _insertNode(this->l_next,content);

return btn;

}

else

{

btn->r_next = _insertNode(this->r_next,content);

return btn;

}

}

public:

BinaryTreeNode(int content){

this->content = content;

l_next = TNULL;

r_next = TNULL;

}

void insertNode(int content)

{

cout << "Aufruf _insertNode von insertNode()\n";

_insertNode(this,content);

}

};

int main(int argc, char *argv[])

{

BinaryTreeNode *root = new BinaryTreeNode(100);

root->insertNode(1);

root->insertNode(19);

root->insertNode(10);

root->insertNode(18);

}

Du darfst für den rekursiven Aufruf nicht this benutzen, denn das ist und bleibt immer der Wurzelknoten. Nimm statt dessen btn, dann sollte das passen.

Und lass die Finger von Dev-C++. Diese IDE wird seit Jahren nicht mehr weiterentwickelt. Nimm Code::Blocks oder MS Visual C++ Express.

  • 1 Monat später...

Hi,

darf ich fragen wo die Aufgabe herkommt?

Ich habe eine exakt identische, welche ich lösen muss.

Die Klasse sieht genau gleich aus.

Nun soll man rekursive private Methoden schreiben, um die Nodes und die Höhe zu zählen.

Nur wie geht das?

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.