C language (splay_tree.h)

Source: Internet
Author: User

/* Splay_tree.h -- stretch tree header file */</P> <p>/* data type definition */<br/> typedef int item; <br/> typedef struct node <br/> {<br/> item; <br/> struct node * left; <br/> struct node * right; <br/>} node; <br/> typedef node * position; <br/> typedef node * splaytree; </P> <p>/* interface function declaration */</P> <p>/* operation: before initializing an extension tree */<br/>/* operation: ptree points to an extension tree */<br/>/* operation: the tree is initialized as null */<br/> void iintializesplaytree (splaytree * ptree); </P> <p>/* operation: determine whether an extension tree is empty */<br/>/* before the operation: the tree is an initialized extension tree */<br/>/* after the operation: if the tree is empty, 1 is returned; otherwise, 0 */<br/> int splaytreeisempty (const splaytree) is returned; </P> <p>/* operation: determine whether an extension tree is full */<br/>/* before the operation: (this function does not accept any parameters) */<br/>/* after the operation: if the tree is full, 1 is returned; otherwise, 0 */<br/> int splaytreeisfull (void) is returned; </P> <p>/* operation: add a node (non-recursive) to the tree */<br/>/* before the operation: the tree is an initialized stretch tree, item is an item type data */<br/>/* operation: if possible, the node with the item data is added to the tree and the root node of the new tree is returned; otherwise, the original tree */<br/> splaytree additem (splaytree tree, const item) is returned. </P> <p>/* operation: Add a node to the tree (recursion) */<br/>/* before the operation: tree is an initialized stretch tree, and item is an item type data */<br/>/* after the operation: if possible, the node with item data is added to the tree and the root node of the new tree is returned; otherwise, the original tree */<br/> splaytree insert (splaytree, const item) is returned ); </P> <p>/* operation: locate the maximum data node in the tree */<br/>/* before the operation: tree is an initialized stretch tree */<br/>/*: if possible, return the pointer to the maximum data node in the tree; otherwise, null */<br/> position findmax (const splaytree tree) is returned. </P> <p>/* operation: locate the minimum data node in the tree */<br/>/* before the operation: the tree is an initialized stretch tree */<br/>/* after the operation: if possible, return the pointer to the smallest data node in the tree; otherwise, return NULL */<br/> position findmin (const splaytree); </P> <p>/* operation: search for the specified data node and place it at the root node */<br/>/* before the operation: tree is an initialized stretch tree, item is the specified data to be searched */<br/>/*: if possible, the node to be searched is used as the root node and the node is returned; otherwise, the original tree */<br/> splaytree find (splaytree tree, const item) is returned. </P> <p>/* operation: search for the specified data node and place it in the following node location (using the stack) */<br/>/* before the operation: tree is an initialized stretch tree, item is the specified data to be searched */<br/>/*: if possible, the found node is used as the heel node and the node is returned; otherwise, the original tree */<br/> splaytree find_by_use_stack (splaytree, const item) is returned. </P> <p>/* operation: before deleting the node where the specified data is located */<br/>/*: the tree is an initialized stretch tree, item is the specified Deleted Data */<br/>/*: if possible, if the node with the item data is deleted, the node of the new tree is returned; otherwise, the original tree */<br/> splaytree Delete (splaytree, const item) is returned. </P> <p>/* operation: apply a function to all nodes in the tree in the middle order */<br/>/* before the operation: tree is an initialized extension tree, And pfun points to a non-return value, after receiving the parameter */<br/>/* of the item type information: this function is used to act on all nodes in the tree in a central order. */<br/> void inordertraversal (const splaytree tree, void (* pfun) (const item ));

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.