|
|
1.1 ! root 1: /******************************************************************* ! 2: * * ! 3: * File: CIFPLOT/tree.c * ! 4: * Written by Dan Fitzpatrick * ! 5: * copyright 1980 -- Regents of the University of California * ! 6: * * ! 7: ********************************************************************/ ! 8: ! 9: #include <stdio.h> ! 10: #include "defs.h" ! 11: #include "globals.h" ! 12: #include "structs.h" ! 13: #include "out_structs.h" ! 14: ! 15: FixTree(e,f) ! 16: TreeElement *e; ! 17: real (*f)(); ! 18: { ! 19: TreeElement *temp,*root; ! 20: ! 21: if(e->son[3] == NIL) return; ! 22: temp = GetTree(); ! 23: temp->type = NODE; ! 24: temp->back = e->back; ! 25: temp->son[0] = e->son[2]; temp->Largest[0] = e->Largest[2]; ! 26: temp->son[1] = e->son[3]; temp->Largest[1] = e->Largest[3]; ! 27: temp->son[2] = temp->son[3] = e->son[2] = e->son[3] = NIL; ! 28: if(e->back == NIL) { ! 29: /* e was the root; must create new root */ ! 30: root = GetTree(); ! 31: root->back = NIL; ! 32: e->back = temp->back = root; ! 33: root->son[0] = e; root->Largest[0] = e->Largest[1]; ! 34: root->son[1] = temp; root->Largest[1] = temp->Largest[1]; ! 35: root->son[2] = root->son[3] = NIL; ! 36: return; ! 37: } ! 38: InsertTree(temp,temp->back,f); ! 39: } ! 40: ! 41: InsertTree(e,r,f) ! 42: TreeElement *e,*r; ! 43: real (*f)(); ! 44: { ! 45: real v; ! 46: ! 47: v = ValueTree(e); ! 48: for(i=0; i<4; i++); ! 49: if(v < r->Largest[i]) { ! 50: for(j=3; j>i; j--) { ! 51: r->son[j] = r->son[j-1]; ! 52: r->Largest[j] = r->Largest[j-1]; ! 53: } ! 54: r->Largest[i] = v; ! 55: r->son[i] = e; ! 56: break; ! 57: } ! 58: FixTree(r,f); ! 59: } ! 60: ! 61: real ! 62: ValueTree(t,f) ! 63: TreeElement *t; ! 64: real (*f)(); ! 65: { ! 66: if(t->type == NODE) ! 67: if(t->son[3] == NIL) ! 68: return(t->Largest[2]); ! 69: else ! 70: return(t->Largest[3]); ! 71: return((*f)(t)); ! 72: } ! 73: ! 74: FindTree(t,v,r) ! 75: TreeElement *t,*r; ! 76: real v; ! 77: { ! 78:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.