All pastes #957218 Raw Edit

Someone

public c v1 · immutable
#957218 ·published 2008-03-25 21:05 UTC
rendered paste body
/* struct.h */                                                                                                                                                                                                                                                                                                                                                                                                                          /*   Example:                                                                                                                                                                                                        *   s-expression:                                                                                                                                                                                                   *       (+ 1 2 3 (* 3 4))                                                                                                                                                                                           *   equivalent s-expression, expressed as the data structure:                                                                                                                                                       *   (cons                                                                                                                                                                                                           *       '+                                                                                                                                                                                                          *       (cons                                                                                                                                                                                                       *           '1                                                                                                                                                                                                      *           (cons                                                                                                                                                                                                   *               '2                                                                                                                                                                                                  *               (cons                                                                                                                                                                                               *                   '3                                                                                                                                                                                              *                   (cons                                                                                                                                                                                           *                       '*                                                                                                                                                                                          *                       (cons                                                                                                                                                                                       *                           '3                                                                                                                                                                                      *                           '4))))))                                                                                                                                                                                *    equivalent binary tree:                                                                                                                                                                                        *       a                                                                                                                                                                                                           *      /                                                                                                                                                                                                            *     b                                                                                                                                                                                                             *    / \                                                                                                                                                                                                            *   +   c                                                                                                                                                                                                           *      / \                                                                                                                                                                                                          *     1   d                                                                                                                                                                                                         *        / \                                                                                                                                                                                                        *       2   e                                                                                                                                                                                                       *          / \                                                                                                                                                                                                      *         3   f                                                                                                                                                                                                     *            / \                                                                                                                                                                                                    *           g  nil                                                                                                                                                                                                  *          / \                                                                                                                                                                                                      *         *   h                                                                                                                                                                                                     *            / \                                                                                                                                                                                                    *           3   i                                                                                                                                                                                                   *              / \                                                                                                                                                                                                  *             4  nil                                                                                                                                                                                                *  */                                                                                                                                                                                                                                                                                                                                                                                                                                  struct exp                                                                                                                                                                                                          {                                                                                                                                                                                                                       enum { B_NODE, L_NODE } e;  /* If L_NODE, v should be null */                                                                                                                                                       struct exp* car,            /* Points to the first element of a list */                                                                                                                                                 * cdr;                  /* Points to the rest of the list */                                                                                                                                                    char* v;                    /* If B_NODE, this should point somewhere */                                                                                                                                        }