Donnerstag, 21. März 2013

Baum in C++

//============================================================================
// Name        : BaumDemo.cpp
// Author      : Ahmad Abdul Latif Yahya
// Version     : 1.0
// Description : Baum in C++, Ansi-style
//============================================================================

#include // hier kommt  iostream, die Schreibweise mit < > wurde hier nicht erkannt
#include // hier kommt cstdlib

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;
}

Montag, 21. November 2011

Saying

"If you born poor it's not your mistake, BUT if you die poor it's your mistake" - Bill Gates-

"In a day, when you don't across any problems, you can be sure that you are traveling in a wrong path" -Swami Vivekananda-

"Three sentences for getting success:

a) Know more than other

b) work more than other

c) expect less than other"

-William Shakesphere-

"If you win you don't need to explain but if you lose you should not be there to explain" -Adolph Hitler-

"Don't compare yourself with anyone in this world, if you do so you are insulting yourself" -Alen Strike-

"Winning doesen't always mean being first winning means you're doing better than you're done before" -Bonnie Blair-

"I will not say I failed 1000 times, I will say that I discoverd there are 1000 ways that can cause failure" -Thomas Edison-

"Everyone thinks of changing the world, but no one thinks of changing himself" -Leo Tolstoy-

"Believing everybody is dangerous; believing nobody is very dangerous" -Abraham Lincon-

"If someone feels that he has never made a mistake in his life, then it means he has never tried a new thing in his life" -Einstein-

"Never break four things in your life- Trust, Promise, Relation & Heart- because when they have been broken thay don't make noise but pains a lot" -Charles-

"If you start judging people you will be having no time to love them" -Mother Teresa-

Donnerstag, 6. Mai 2010