// Name : BaumDemo.cpp
// Author : Ahmad Abdul Latif Yahya
// Version : 1.0
// Description : Baum in C++, Ansi-style
//============================================================================
#include
using namespace std;
typedef int TDaten;
typedef struct Knoten
{
Knoten* l;
Knoten* r;
void* daten;
}Knoten;
Knoten* createNode(Knoten* left, Knoten* right, TDaten daten)
{
Knoten* node = new Knoten;
if (node == NULL)
{
cerr << "Out of Memory?" << endl;
exit(-1);
}
node->l = left;
node->r = right;
node->daten = new TDaten;
*((TDaten*)node->daten) = daten;
return node;
}
int main() {
Knoten* root = NULL;
Knoten* blatt1 = createNode(NULL, NULL, 1);
Knoten* blatt2 = createNode(NULL, NULL, 2);
Knoten* blatt3 = createNode(NULL, NULL, 3);
Knoten* blatt4 = createNode(NULL, NULL, 4);
Knoten* node1 = createNode(blatt1, blatt2, 5);
Knoten* node2 = createNode(blatt3, blatt4, 6);
root = createNode(node1, node2, 7);
cout << "Inorder Ausgabe: " << *((TDaten*)root->l->daten) << " " << *((TDaten*)root->daten) << " "
<< *((TDaten*)root->r->daten) << endl;
cout << "Preorder Ausgabe: " << *((TDaten*)root->daten) << " " << *((TDaten*)root->l->daten) << " "
<< *((TDaten*)root->r->daten) << endl;
cout << "Postorder Ausgabe: " << *((TDaten*)root->l->daten) << " " << *((TDaten*)root->r->daten) << " "
<< *((TDaten*)root->daten) << endl;
return 0;
}