Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. typedef struct node *link;
  2. typedef struct bst *BST
  3. struct node {
  4.     int N;
  5.     ITEM item;
  6.     link parent,left,right;
  7. };
  8. struct bst {
  9.     int N;
  10.     link head,nodo_fittizio;
  11. };
  12. static char buffer[MAXS];
  13.  
  14. BST BSTreadPreorder(FILE *file) {
  15.     BST tree;
  16.    
  17.     tree=crea_BST();
  18.     tree->head=BSTreadPreorderR(file,tree->head);
  19.     return tree;
  20. }
  21. link BSTreadPreorderR(FILE *file,link x) {
  22.     int figlio_destro,figlio_sinistro;
  23.  
  24.     fscanf(file," %s %d %d %d",buffer,numero(x->item),&figlio_destro,&figlio_sinistro);
  25.     inserisci_chiave(x->item,buffer);
  26.     if(figlio_sinistro) {
  27.         x->left=nuovo_nodo(crea_ITEM(),x,NULL,NULL,1);
  28.         x->left=BSTreadPreorderR(file,x->left);
  29.     }
  30.     if(figlio_destro) {
  31.         x->right=nuovo_nodo(crea_ITEM(),x,NULL,NULL,2);
  32.         x->right=BSTreadPreorderR(file,x->right);
  33.     }
  34.     return x;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement