/***************** run Environment:http://www.anycodes.cn/zh/ content: cardinality tree ************* / #include <stdio.h> #include <stdlib.h>typedef struct radixnode { char *str; struct radixnode *lchild , *rchild; } radixnode;void radix_insert (RADIXNODE&NBSP;*NODE,&NBSP;CHAR&NBSP;*STR) { int i; for (i = 0; str[i] ! = ' + '; i++) { if (str[i] == ' 0 ') { if ( Node->lchild == null) node->lchild = (radixnode*) calloc (sizeof (Radixnode), 1); node = node->lchild; } else { if ( Node->rchild == null) node->rchild = (radixnode*) calloc (sizeof ( Radixnode), 1); node = node->rchild; } } node->str = str;} Void radix_preorder_walk (Radixnode *node) { if (node != NULL) { if (node->str != NULL) printf ("%s\n", &NBSP;NODE->STR); radix_preorder_walk (node-> Lchild); radix_preorder_walk (Node->rchild); }}int main (void) { radixnode *root = (radixnode*) malloc (sizeof (Radixnode)), char ss[5][5]={"01", "011", "101" , "1010", "1011"}; radix_insert (Root, ss[0]); radix_insert (Root, ss[1]); radix_insert (root, ss[2]); radix_insert (Root, ss[3]); radix_ Insert (root, ss[4]); radix_preorder_walk (Root); return 1;}
Original http://blog.csdn.net/dc_726/article/details/7391988
Modification eliminates errors caused by warnings and certain compilers
Small code to Master learning Motoki