Binary Tree chain Storage Structure-binary linked list

Source: Internet
Author: User

Binary Tree chain Storage Structure-binary linked list

Only the header file is attached here:

The Code has been shared in the resource:

Address: http://download.csdn.net/detail/ta893115871/4751186

Header file:

/** Tree. h ** created on: 2012-10-31 * Author: China * QQ: 893115871 ** using a linked list can avoid space waste in sequential storage. The algorithm and structure are relatively simple, but the binary linked list is used, * Due to the lack of guidance on the parent node, You need to scan the tree again to learn the Node Address of the parent node When retrieving the parent node. */# Ifndef tree_h _ # define tree_h _ # include <stdio. h> # include <stdlib. h> // For malloc () # include <math. h> // for overflow the value is 3 # define OK 1 # define error 0 # define nil '#' // It indicates an empty node # define root-1 # define sibling 2 typedef int status; /* status is the function type, and its value is the function result status code, such as OK * // The binary linked list storage of the Binary Tree indicates */typedef char datatype; typedef struct tnode {datatype data; // The data stored by the node struct tnode * lchild, * rchild;/* The left and right children refer to the parent */} bitnode, * bitree; // ------------ queue definition and basic operation declaration, used to traverse Binary Tree ---------------------------------- typedef bitree qelemtype; // The queue element is Pointer typedef struct snode {qelemtype data; struct snode * Next ;} qnode, * linklist; typedef struct {linklist front; // The first node of the Team (that is, the delete point) linklist rear; // The End Node (that is, the insertion point)} linkqueue; int Queue (linkqueue *); int linkqueue_empty (const linkqueue *); int linkqueue_length (const linkqueue *); int Queue (const linkqueue *, qelemtype *); int linkqueue_enter (linkqueue *, qelemtype); int linkqueue_delete (linkqueue *, qelemtype *); void linkqueue_clear (linkqueue *); void destroyqueue (linkqueue *); // your end queue contains bitree create_bitree (); // create a binary tree status empty_bitree (const bitree); // empty // visitvoid visit_func_bitree (datatype); // output node element void pre_order_bitree (const bitree, void (* visit) (datatype); // first traverse the binary tree void in_order_bitree (const bitree, void (* visit) (datatype); // traverse the binary tree void post_order_bitree (const bitree, void (* visit) (datatype); // post-order traversal of the Binary Tree void level_order_bitree (const bitree, void (* visit) (datatype )); // level traversal Binary Tree void level_order_bitree_queue (const bitree, void (* visit) (datatype); // level traversal Binary Tree void pre_orderlists_bitree (const bitree, void (* visit) (datatype); // generalized table output binary tree // end visitstatus destroy_bitree (bitree ); // destroy the binary tree # define clear_bitree destroy_bitree // clear and destroy the same int depth_bitree (const bitree) in the binary tree; // obtain the depth int depth_bitree2 (const bitree) of the binary tree ); // obtain the depth status get_rootdata (const bitree, datatype *) of the binary tree; // obtain the data status get_parent_bitree (const bitree, datatype *, datatype) of the root node ); // obtain the parent node status get_leftchild_bitree (const bitree, datatype *, datatype); // obtain the left child status get_rightchild_bitree (const bitree, datatype *, datatype) of the node ); // get the right child status of a node get_leftsibling_bitree (const bitree, datatype *, datatype); // obtain the left sibling status get_rightsibling_bitree (const bitree, datatype *, datatype) of the node ); // obtain the right brother of the node status assign_bitree (bitree, datatype, datatype); // modify the value of a node int get_nums_bitree (const bitree ); // return the number of knots in the binary tree int get_leafnums_bitree (const bitree); // return the number of leaves in the binary tree status get_node_bitree (const bitree, datatype *, INT ); // obtain the status search_node_bitree (const bitree, datatype) of the index node in the first order; // check whether the tree contains a certain node void exchange_bitree (bitree ); // switch left and right subtree void delete_bitree (bitree, datatype, INT); // Delete subtree void insert_bitree (bitree, datatype, Int, const bitree ); // Insert the subtree # endif/* tree_h _*/

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.