volevo fare un albero di puntatori a void. ora, l'inserimento va, cioè nn da errori, ma secondo me nn salva nulla, la stampa invece nn so come implementarla..
codice:
tree.h
#ifndef TREE_H
#define TREE_H
struct nodo;
typedef nodo * tree;
typedef void * elemento ;
struct nodo{
elemento item;
tree left;
tree right;
};
void init(tree & );
int inserisci(tree &,elemento );
void stampa(tree );
#endif
codice:
tree.cpp
using namespace std;
#include <iostream>
#include "tree.h"
void init(tree & t){
t = NULL;
}
int inserisci(tree & t,elemento it){
elemento e;
if (t==NULL){
t=new nodo;
if (t==NULL) return 0;
}
else {
if (t->item==NULL) {
e = new elemento;
if (e==NULL) return 0;
e=it;
t->item=e;
t->left=NULL;
t->right=NULL;
}
else if (it>t->item) return inserisci (t->right,it);
else return inserisci (t->left,it);
}
}
void stampa(tree t){
if (t!=NULL){
stampa(t->left);
cout << (int)t->item << endl;
stampa(t->right);
}
}
codice:
main.cpp
using namespace std;
#include <iostream>
#include "tree.h"
int main(){
tree t;
int ele;
init(t);
ele=100;
inserisci(t,&ele);
stampa(t);
return 1;
}