Box tree header file C Language

Source: Internet
Author: User

Two days later, I watched the virtual memory during the day and wrote it at home in the evening. I just finished writing it. There are many disadvantages, and functional implementation is necessary.

This item was written according to the requirements of the exercise. I gave it a name-the box tree.

In the process of writing code, I hope to celebrate it after writing it. After writing it, I feel nothing...

For this, I will explain my analysis.

The general requirement is that the request is ordered. So I chose the Binary Search Tree and considered the AVL Tree. Later I thought that the new things would be implemented simply first.

Later, according to the actual situation in the writing process, I wrote a lot of simulation at. This pseudo code first came out, although it was modularized by me later.

I'm glad that I thought about the sequential search of the binary search tree. This is my pleasure. I think this is the essence.

This is basically the case. I have created this thing based on my requirements and existing knowledge, and I have a great sense of accomplishment. I am very happy!

I don't know if my implementation is the best solution, although it is limited to my current knowledge level.

For future study, I decided to give time complexity for each set of ADTs. although the current data cannot be accurate. in addition, I decided to review what I learned from time to time. I wrote Delete () and it was stuck. I hope I can do this. it is a pleasure.

Don't talk about it. smoke too much and paste the code.

/* Box. H -- box problem header file */<br/> # include <stdio. h> <br/> # include <stdlib. h> </P> <p> # define generic 10 <br/> # define left 1 <br/> # define right 2 </P> <p>/* Data Type define */</P> <p> typedef int weight; // weight <br/> typedef struct box <br/>{< br/> weight unoccupied; // available weight <br/> weight capacity; // capacity <br/> struct box * parent; <br/> struct box * left; <br/> struct box * right; <br/>} box; <br/> typedef struct boxtree <br/> {<br/> box * root; <br/> weight usual; // average weight <br/> int size; <br/>} * boxtree; </P> <p>/* interface function declaration */</P> <p>/* operation: before creating and initializing a boxtree */<br/>/* operation: After PBT points to a boxtree */<br/>/* operation: if the memory allocation is successful, create and initialize a boxtree. The default capacity is capacity and 1 is returned. Otherwise, 0 */<br/>/* time complexity: O (1) is returned) */<br/> int initializeboxtree (boxtree * const PBT, const weight capacity); </P> <p>/* operation: determine whether a boxtree is empty */<br/>/* before the operation: PBT points to an initialized boxtree */<br/>/* after the operation: if the boxtree is empty, 1 is returned; otherwise, 0 */<br/>/* time complexity: O (1) is returned) */<br/> int boxtreeisempty (const boxtree * const PBT); </P> <p>/* operation: reduce the value of the maximum keyword> = triangle in the specified boxtree */<br/>/* before the operation: PBT points to an initialized boxtree, triangle is the weight */<br/>/* operation: if the memory allocation is successful during the operation, 1 is returned; otherwise, 0 */<br/>/* time complexity is returned: O (2 logn) */<br/> int dealwiththebiggest (boxtree * const PBT, const weight triangle ); </P> <p>/* operation: reduce the value of the smallest keyword = triangle in the specified boxtree */<br/>/* before the operation: PBT points to an initialized boxtree. Triangle indicates the weight of the loaded boxtree. */<br/>/*: if the memory is allocated successfully during the operation, 1 is returned; otherwise, 0 */<br/>/* time complexity is returned: O (7 logn) */<br/> int dealwiththesmallest (boxtree * const PBT, const weight triangle ); </P> <p>/* operation: In the middle order, a function is applied to all nodes in a boxtree. */<br/>/* before the operation: PBT points to an initialized boxtree, and pfun points to a function that does not return a value. After receiving a box * type parameter */<br/>/* operation: the function pointed to by pfun is applied to all nodes in the boxtree in a forward order once */<br/>/* time complexity: O (logn) */<br/> void inordertraversal (const box * const box, void (* pfun) (const box * const box); </P> <p>/* operation: release the memory space occupied by a boxtree */<br/>/* before the operation: PBT points to an initialized boxtree */<br/>/* after the operation: the memory space occupied by the boxtree is released */<br/>/* time complexity: O (1) */<br/> void release (const boxtree * const PBT ); <br/>

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.