本人写的trinode模板-就是3叶节点 如下 欢迎评论,方便本人修改 代码如下: #ifndef G_GSTL_TRINODE_HPP #define G_GSTL_TRINODE_HPP #if _MSC_VER > 1000 #pragma once #endif #include "math.hpp" #ifdef _MSC_VER #pragma pack(push,8) #endif namespace g { namespace gstl { template<typename T1, typename T2, typename T3> struct trinode { typedef T1 ltype; typedef T2 mtype; typedef T3 rtype; trinode(): lvalue(0), mvalue(0), rvalue(0) {} trinode(const ltype &_lvalue, const mtype &_mvalue, const rtype &_rvalue): lvalue(_lvalue), mvalue(_mvalue), rvalue(_rvalue) {} trinode(const trinode<ltype, mtype, rtype> &_obj): lvalue(_obj.lvalue), mvalue(_obj.mvalue), rvalue(_obj.rvalue){} trinode& operator = (const trinode<ltype, mtype, rtype> &_obj) { trinode obj(_obj); return *this; } void swap(trinode<ltype, mtype, rtype> &_rhs) { g::math::swap<ltype>(lvalue, _rhs.lvalue); g::math::swap<mtype>(mvalue, _rhs.mvalue); g::math::swap<rtype>(rvalue, _rhs.rvalue); } public: ltype lvalue; mtype mvalue; rtype rvalue; }; template<typename T1, typename T2, typename T3> bool __cdecl operator == (const trinode<T1, T2, T3> &rhs, const trinode<T1, T2, T3> &ths) { return (rhs.lvalue == ths.lvalue && rhs.mvalue == ths.mvalue && rhs.rvalue == ths.rvalue); } template<typename T1, typename T2, typename T3> bool __cdecl operator != (const trinode<T1, T2, T3> &rhs, const trinode<T1, T2, T3> &ths) { return !(rhs==ths); } } // end gstl } //end g namespace #ifdef _MSC_VER #pragma pack(pop) #endif /* _MSC_VER */ #endif 正如代码所示 支持默认构造函数,复制构造函数,赋值构造函数 另外还有交换和判定是否相等的函数 -_-