All pastes #957519 Raw Edit

Untitled

public text v1 · immutable
#957519 ·published 2008-03-26 01:14 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                                                                                                                                                                                                      
 *          / \                                                                                                                                                                                                     
 *         *   h                                                                                                                                                                                                    
 *            / \                                                                                                                                                                                                   
 *           3   i                                                                                                                                                                                                  
 *              /                                                                                                                                                                                                   
 *             4                                                                                                                                                                                                    
 *  */                                                                                                                                                                                                              
                                                                                                                                                                                                                    
struct exp                                                                                                                                                                                                          
{                                                                                                                                                                                                                   
    enum { NIL, B_NODE, L_NODE } e;                                                                                                                                                                                 
    void* car,                  /* points to the first element of the list */                                                                                                                                       
        * cdr;                  /* Points to the rest of the list */                                                                                                                                                
};                                                                                                                                                                                                                  
                                                                                                                                                                                                                    
void exp_init( struct exp* );                                                                                                                                                                                       
void exp_destroy( struct exp* );