Many of the data structure of the book on the interpretation of the information structure is implemented by pseudo-code, in fact, it is not intuitive, so for all the data structure operation I will use C to implement it again.
The tree is the basis of learning the binary tree, but also the basis of understanding B-tree, plus tree, the following is a few simple operation of the tree, easy to understand.
Data
//-------数据结构----------------------------------------#define m 3 //定义度为3的树typedefchar datatype;typedefstruct node{ datatype data; struct node* child[m];}treenode;//------------------------------------------------------
Basic operations
//--------operation------------------------------------------voidPreorder (treenode* t) {intIif(t) {printf("%c", T->data); for(i=0; i<m;i++) {preorder (t->child[i]); } }}voidPostorer (treenode* t) {intIif(t) { for(i =0; i<m;i++) {postorer (t->child[i]); }printf("%c", T->data); }}//must use a pointer pointer, if the argument is a pointer, the parameter is just a copy of the argument pointer, so the value of the argument pointer is not changed. voidCreatetree (treenode** p) {//input directly to ab## #C # # #D # # # #回车 intICharChscanf("%c", &ch);if(ch = =' # ') {*p = NULL; }Else{*p = (treenode*)malloc(sizeof(node)); (*p)->data = ch; for(i =0; i<m;i++) {Createtree (& (*p)->child[i]); } }}//------------------------------------------------------
For the operation of the tree does not need to do too much, most of them are for the operation of the binary tree, so give a few simple operations, enough.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
A simple collection of tree operations--based on C implementation