Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**** LIST_H ****/
- #ifndef LIST_H
- #define LIST_H
- #include "tree.h"
- typedef struct List
- {
- ptree info;
- struct List *next;
- }list;
- typedef list *plist;
- int contExpr(plist, int);
- #endif /* LIST_H */
- *****************************
- /**** LIST_C ****/
- #include "list.h"
- int contExpr(plist p, int v)
- {
- int cont = 0;
- while(p != NULL)
- {
- if(resolve(p->info) > v)
- cont++;
- }
- return cont;
- }
- *****************************
- /**** TREE_H ****/
- #ifndef TREE_H
- #define TREE_H
- #include <stdlib.h>
- #include <stdio.h>
- typedef struct node
- {
- int info;
- struct node *dx, *sx;
- }tree;
- typedef tree *ptree;
- int resolve(ptree);
- #endif /* TREE_H */
- *****************************
- /**** TREE_C ****/
- #include "tree.h"
- int resolve(ptree t)
- {
- if(!t->dx && !t->sx)
- return t->info;
- int val_sx, val_dx;
- val_sx = resolve(t->sx);
- val_dx = resolve(t->dx);
- switch(t->info)
- {
- case '+':
- return val_sx + val_dx;
- break;
- case '*':
- return val_sx * val_dx;
- break;
- case '-':
- return val_sx - val_dx;
- break;
- default:
- return val_sx / val_dx;
- }
- return 0;
- }
- *****************************
- /**** LOGICTREE_H ****/
- #ifndef LOGICTREE_H
- #define LOGICTREE_H
- #include "tree.h"
- #include "list.h"
- typedef struct log_tree
- {
- ptree info;
- struct log_tree *sx, *dx;
- }logictree;
- typedef logictree *plogic;
- void inserisci(ptree, plogic);
- plogic createP_ABR(plist);
- #endif /* LOGICTREE_H */
- *****************************
- /**** LOGICTREE_C ****/
- #include "logictree.h"
- void inserisci(ptree p, plogic l)
- {
- if(!l)
- {
- l = malloc(sizeof(logictree));
- l->info = p;
- l->dx = NULL;
- l->sx = NULL;
- }
- else
- {
- if(resolve(p) > resolve(l->info))
- inserisci(p, l->dx);
- else
- inserisci(p, l->sx);
- }
- }
- plogic createP_ABR(plist p)
- {
- plogic l = malloc(sizeof(logictree));
- l = NULL;
- while(p != NULL)
- inserisci(p->info, l);
- return l;
- }
- *****************************
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement