home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 155_01 / btree.h < prev    next >
C/C++ Source or Header  |  1990-10-09  |  3KB  |  68 lines

  1.  
  2. /* Author: Ray Swartz
  3.  *         P.O. Box 2528
  4.  *         Santa Cruz, Calif. 95063
  5.  * Last Modified: 4/28/85
  6.  *
  7.  * ANY USE OF THESE LIBRARY ROUTINES EITHER PERSONAL OR COMMERCIAL
  8.  * IS ALLOWED UPON THE CONDITION THAT THE USER IDENTIFY THEM
  9.  * AS BEING USED IN THE PROGRAM.  IDENTIFYING INFORMATION MUST
  10.  * APPEAR IN THE PROGRAM DOCUMENTATION OR ON THE TERMINAL SCREEN.
  11.  *
  12.  *         #################################    
  13.  *         # UNATTRIBUTED USE IS FORBIDDEN #
  14.  *         #################################
  15.  *
  16.  */
  17.  
  18. /* Modifier: Honma Michimasa
  19.  *    Higashi Kamagaya 2-6-54
  20.  *    Kamagayashi, Chiba, Japan, 273-01
  21. */
  22.  
  23. #define NOT_FOUND   -1
  24. #define AT_END      -2
  25. #define YES          1
  26. #define NO           0
  27. #define TOP         -1   /* flag to show if top of list = rotate node */
  28. #define END          0   /* end pointer in a node */
  29. #define QUIT         0   /* menu options */
  30. #define FIND         1
  31. #define INSERT       2
  32. #define NEXT         3
  33. #define PREVIOUS     4
  34. #define DELETE       5
  35. #define FIRST        6
  36. #define LAST         7
  37. #define CLEAR_LINE           printf("\033[K")   /* for MS-DOS machine */
  38. #define CLS                  printf("\033[2J")  /* for MS-DOS machine */
  39. #define BELL                 putchar(0x07);
  40. #define DATA_LENGTH 19  /* characters in first record of key file */
  41. #define MAX_NODES 100000 /* maximum nodes allowed in a keyfile */
  42.  
  43. struct keyinfo {   /* Header information on each open keyfile */
  44.     FILE *file;          /* file pointer to keyfile */
  45.     int keylength;       /* Length of file key */
  46.     long next_avail;     /* Next free node in tree (nbr_in_list + 1) */
  47.     long list_head;      /* Node number at the head of the list */
  48.     long nbr_in_list;    /* Number of (active) nodes in the tree */
  49. };
  50.  
  51. struct node {      /* The composition of a tree-node */
  52.     long rec_nbr;        /* The pointer to the data file record */
  53.     long left_link;      /* The node to this one's immediate left */
  54.     long right_link;     /* The node to this one's immediate right */
  55.     char *key;           /* Pointer to this record's key */
  56.     int delete_flag;     /* 1 if deleted, 0 if live */
  57.     int balance;         /* -1 left subtree longer, 0 even, +1 right bigger */
  58. };
  59.  
  60.  
  61. #define STACK_LENGTH 50    /* length of history stacks */  
  62.  
  63. typedef struct stack {    /* tree traversal stack */
  64.     long element[STACK_LENGTH];   /* Node number pushed onto history stack */
  65.     int level[STACK_LENGTH];      /* Stack level of this element */
  66.     int stack_cntr;               /* Top of stack */
  67. } STACK;
  68.