Binary Search Tree linked list header file C Language

Source: Internet
Author: User

/* 17-8-09-11-21.20.h -- Chapter 8 Question */<br/> # ifndef last_h _ <br/> # define add_an_item 1 <br/> # define size 20 </P> <p>/* define the data type */<br/>/* name_and_pet data type exposed to the user */<br/> typedef struct name_and_pet <br />{< br/> char petname [size]; /* pet name */<br/> char petkind [size];/* pet type */<br/>} name_and_kind; <br/> typedef struct item <br/> {<br/> name_and_kind; <br/> struct item * Next; <br/>} item; <br/> typedef struct node <br/> {<br/> item * item; <br/> struct node * left; <br/> struct node * right; <br/>} node; <br/> typedef node * tree; </P> <p>/* interface function declaration */</P> <p>/* operation: before initializing a tree as an empty tree */<br/>/*: Point ptree to a tree */<br/>: the tree is initialized as an empty tree */<br/> void inatializetree (TREE * const ptree); </P> <p>/* operation: determine whether the tree is empty */<br/>/* before the operation: ptree points to a tree */<br/>/* after the operation: if the tree is empty, return 1; otherwise, 0 */<br/> int treeisempty (const tree * const ptree) is returned. </P> <p>/* operation: before adding a project to the tree */<br/>/*: pitem points to the data to be added, ptree points to an initialized binary search tree */<br/>/*: if possible, point data to pitem and add it to the tree. A node may be added, it may also be added to the next pointer of the node, and 1 is returned; otherwise, 0 */<br/> int insert (TREE * const ptree, const name_and_kind * const p_name_and_pet) is returned ); </P> <p>/* operation: returns the pointer to the leftmost node in the tree */<br/>/* before the operation: ptree points to an initialized binary search tree */<br/>/* after the operation: returns the pointer to the leftmost node in the tree */<br/> node * findmin (const tree * const ptree); </P> <p>/* operation: returns the pointer to the rightmost node in the tree */<br/>/* before the operation: ptree points to an initialized binary search tree */<br/>/* after the operation: returns the pointer to the rightmost node in the tree */<br/> node * findmax (const tree * const ptree); </P> <p>/* operation: delete a node or item data with the specified name_and_kind type from the tree */<br/>/* before the operation: ptree points to an initialized Binary Search Tree, p_name_and_kind points to data of the item type */<br/>/*: if possible, delete a node with p_name_and_kind pointing to data from the tree or a name_and_kind type data pointed to by the node pointer, and return the new tree; otherwise, the original tree */<br/> tree Delete (TREE * const ptree, name_and_kind * p_name_and_kind) is returned. </P> <p>/* operation: returns a pointer to a node with the specified name_and_kind.petname type data. */<br/>/* before the operation, the tree is an initialized Binary Search Tree, p_name_and_kind is a pointer to name_and_kind type data */<br/>/*: if possible, return a pointer to this node; otherwise, null */<br/> node * seekandreturn (const TREE tree, const name_and_kind * const p_name_and_kind) is returned. </P> <p>/* operation: before accessing each project in the tree in a central order */<br/>/*: ptree points to an initialized Binary Search Tree, and pfun points to a non-return value, after receiving a function */<br/>/* that points to the item pointer type value as a parameter: the function pointed to by pfun applies to each node in the tree in a forward Order */<br/> void inordertraversal (const tree * const ptree, void (* pfun) (const item * const pitem); </P> <p>/* operation: before deleting all nodes in the tree */<br/>/* operation: ptree points to an initialized binary search tree */<br/>/* after the operation: all nodes in the tree are deleted */<br/> // void deleteall (TREE * const ptree); </P> <p> # endif

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.