The Interval Tree is also an extended data structure based on a binary tree. Each node stores the interval information.
This routine is mainly written for the next thing. Of course, it is also worth a long time.
// Intervaltree. H -- Interval Tree header file <br/> # include <iostream> </P> <p> namespace tree <br/>{< br/> typedef int item; <br/> typedef struct node <br/> {<br/> item min, Max; <br/> item maxofall; <br/> int number; <br/> struct node * left, * right; <br/>} node; <br/> const item negative_infinity = 1 <31; <br/> class intervaltree <br/> {<br/> PRIVATE: <br/> node * m_root; <br/> item m_min, m_max; <br/> int m_number; <Br/> bool m_outofspace; <br/> bool m_hasdiscovered; <br/> bool m_overlap (const item min, const item max) const; <br/> item m_max (const item A, const item B, const item c) const; <br/> node * m_makenode (void) const; <br/> node * m_updata (node * const PN) const; <br/> node * m_insert (node * PN ); <br/> node * m_delete (node * PN); <br/> node * m_search (node * PN) const; <br/> int m_searchall (Const node * const PN); <br/> void m_findnewminandmax (const node * PN); <br/> void m_release (const node * const PN) const; <br/> void m_inordertraversal (const node * const PN) const; <br/> Public: <br/> intervaltree (void ); <br/> bool insert (const item min, const item Max, const int number); <br/> bool Delete (const item min, const item max ); <br/> // Following function is the answer of <introd Uction to algorithms Second Edition> 14.3-3 <br/> node * search (const item min, const item max ); <br/> // Following function is the answer of <Introduction to algorithms Second Edition> 14.3-4 <br/> // or it can export element of nodes to screen or other data structural, it's easy. <br/> int searchall (const item min, const item max); <br/> void inordertraversal (void) const; <br/> ~ Intervaltree (void); <br/>}; <br/>}