hi. Im trying to make an expresion tree for every ER that I read
each ER will be transformed into postfix and saved in a string, which I'll be sending to arbol_expresion() to create it`s tree expression

Searching on the web I found a method to convert the postfix expresion to a tree, which says that I have to remember the two nodes, and then, when I read an operator, I assign the two nodes as its childs

I was thinking that the easiest way to do that is by a stack: I create the nodes and save them into the stack, when I read the operator, I read the stack //which contains the pointers to the two nodes
and assign them to the operator's node.

This are my structures:

struct node_ab{   //expression tree structure
   struct node_ab* izq  //left child
   struct node_ab* der
   struct list primerapos
   struct list ultimapos
   int etiqueta
};
typedef struct node_ab abb


struct pila{  //stack
   struct abb* dato
   struct pila *siguiente
}


void insert(string postfix){

if dato!=concatenacion|opcionalidad|cerradura   //if dato is not an operator
   create node //here I set all the pointers of the node
   pila.push(*node)
else
   crear nodo  //here I set all the pointers of the node
   nodo->izq= pila.pop()
   nodo->der= pila.pop()

I dont know what is happening, because it says that I'm working with two different type of variables when I assign the pointers of the nodes saved in the stack to the operator node.

What happened to all the semi-colons? Have the brackets from your if and else vanished as well, or is the code above your actual code?

no, this is my actual code:

//expresion tree structure
typedef struct nodo_ab{
    int etiqueta;
    lista primerapos;
    lista ultimapos;
    char dato;
    struct nodo_ab* izq;
    struct nodo_ab* der;
    struct nodo_ab* padre;
    }nodo_ab;
typedef struct nodo_ab *abb;


//stack 
typedef struct nodo_pila{
    //int dato;
    struct abb* dato;
    struct nodo_pila *sig;
    } nodo_pila;
typedef nodo_pila *pnodo;
typedef nodo_pila *Pila;

//insert method
void insert(string postfix){
   if (dato!=(concatenacion|opcionalidad|cerradura)){ //if dato is not an operator
        *r=(nodo_ab*)malloc(sizeof(nodo_ab));
        (*r)->dato=dato;
        (*r)->izq=NULL;
        (*r)->der=NULL;
        (*r)->etiqueta=NULL;
        (*r)->primerapos=NULL;
        (*r)->ultimapos=NULL;
        pila.push(*r);
   }

   else {
        *r=(nodo_ab*)malloc(sizeof(nodo_ab));
        (*r)->dato=dato;
        (*r)->izq=pila.pop();
        (*r)->der=pila.pop();
        (*r)->etiqueta=NULL;
        (*r)->primerapos=NULL;
        (*r)->ultimapos=NULL;
   }
}

Ok .... What is the issue ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.