Witam!
W jaki sposób dodać wszystkie węzły drzewa binarnego do listy?
Kombinuję tak ale nie bardzo chce to działać:
// Struktura drzewa i listy
struct Tree
{
int weight;
int number;
char c;
Tree* parent;
Tree* left;
Tree* right;
};
struct List
{
List* next;
List* prev;
Tree* t;
};
List* head = 0;
List* tail = 0;
// Dodawanie do listy
void addToList(Tree* t)
{
List* temp = new List;
temp->t = t;
temp->next = head;
temp->prev = 0;
if(head) head->prev = temp;
head = temp;
if(!tail) tail = head;
}
// Tutaj dodaję węzeł do listy
void inOrder(Tree* tw)
{
if(tw->left)
inOrder(tw->left);
addToList(tw);
if(tw->right)
inOrder(tw->right);
}
Proszę o pomoc.
Pozdrawiam, Ziem!