X
#ifndef _BINTREE_
#define _BINTREE
#include <cstddef>
#include <functional>
#include <iterator>
#include <memory>
#include <stdexcept>
#include <xutility>
#include <vector>
#include <stack>
#include <list>
template<class _Ty, class _A = allocator<_Ty> >
class bintree {
protected:
struct _Item;
friend struct _Item;
typedef _POINTER_X(_Item, _A) _Itemptr;
struct _Item{
_Itemptr _Left, _Right, _Parent;
unsigned int _ItemIndex; bool _IfNode;
_Ty _Value;
_Item()
: _ItemIndex(0), _IfNode(false)
_Left(this), _Right(this) {}
};
struct _Acc;
friend struct _Acc;
struct _Acc {
typedef _REFERENCE_X(_Itemptr, _A) _Itempref;
typedef _A::reference _Vref;
static _Itempref _Left(_Itemptr _P)
{return ((_Itempref)(*_P)._Left); }
static _Itempref _Right(_Itemptr _P)
{return ((_Nodepref)(*_P)._Right); }
static _Itempref _Parent(_Itemptr _P)
{return ((_Nodepref)(*_P)._Parent); }
static _Vref _Value(_Itemptr _P)
{return ((_Vref)(*_P)._Value); }
static _Vref _Index(_Itemptr _P)
{return ((_Vref)(*_P)._ItemIndex); }
static _Vref _IfNode(_Itemptr _P)
{return ((_Vref)(*_P)._IfNode); }
};
typedef unsigned int _UInt;
typedef std::list<_UInt> _Way;
// typedef NULL _Nil;
public:
typedef _UInt _Point;
class const_iterator;
friend class const_iterator;
class const_iterator {
public:
const_iterator()
: _Ptr(Head()) {}
/* const_iterator(unsigned int _I)
: _ItemIndex(_I) { } */
_Acc::_Vref operator*() const
{return (_Acc::_Value(_Ptr)); }
/* _Acc::_Vref _GoToParent()
{ _Ptr = _Acc::_Parent(_Ptr);
return (_Acc::_Value(_Ptr)); }
_Acc::_Vref _LeftDown()
{ _Ptr = _Acc::_Left(_Ptr);
return (_Acc::_Value(_Ptr)); }
_Acc::_Vref _RightDown()
{ _Ptr = _Acc::_Right(_Ptr);
return (_Acc::_Value(_Ptr)); }*/
void _GoToParent()
{ _Ptr = _Acc::_Parent(_Ptr);
return (_Acc::_Value(_Ptr)); }
void _LeftDown()
{ _Ptr = _Acc::_Left(_Ptr);
return (_Acc::_Value(_Ptr)); }
void _RightDown()
{ _Ptr = _Acc::_Right(_Ptr);
return (_Acc::_Value(_Ptr)); }
bool _GoToSpecificP(_Point _P)
{ if((_Itemptr _Tmp = calculate_way(_P))
== _NULL()) return false;
_Ptr = _Tmp; }
protected:
//stack<_UInt> _WayStack;
//_UInt _ItemIndex;
_Itemptr _Ptr;
};
bool push(const _Ty &_X, _Point _P, _UInt _Way)
{ if((_Itemptr _Ptr = calculate_way(_P))
== _NULL()) return false;
_Use(_P);
if(_Way == left()) return insert_left(_X, _Ptr);
else if(_Way == right()) return insert_right(_X, _Ptr); }
bool insert_left(const _Ty &_Xr, _Itemptr _Ptr)
{ _Itemptr _Tmp = _ByItem();
_Acc::_Left(_Ptr) = _Tmp;
_Acc::_Parent(_Tmp) = _Ptr;
_Acc::_IfNode(_Ptr) = true;
_Acc::_Index(_Tmp) = _IndexGen();
allocator.construct(&_Acc::_Value(_Tmp), _Xr); return true; }
bool insert_right(const _Ty &_Xr, _Itemptr _Ptr)
{ _Itemptr _Tmp = _ByItem();
_Acc::_Right(_Ptr) = _Tmp;
_Acc::_Parent(_Tmp) = _Ptr;
_Acc::_IfNode(_Ptr) = true;
_Acc::_Index(_Tmp) = _IndexGen();
allocator.construct(&_Acc::_Value(_Tmp), _Xr); return true; }
_UInt left(void)
{ return 1; }
_UInt right(void)
{ return 2; }
NULL _NULL()
{ return NULL; }
protected:
_Itemptr _ByItem(void)
{ _Itemptr _Tmp = allocator._Charalloc(
1 * sizeof (_Item));
return _Tmp; }
void _FreeItem(_Itemptr _S)
{ allocator.deallocate(_S, 1); }
_UInt _IndexGen(_UInt _IP)
{ if(!(_IP % 2))
return ((/*2 * _IP*/ _IP << 2) + 1);
else
return ((/*2 * _IP*/ _IP << 2) + 2); }
_Itemptr calculate_way(_Point _P)
{ if(!_IsValid(_P))
return _NULL();
_Way _L; _PtoP(_P, _L);
return _WalkDown(_L); }
_Itemptr _WalkDown(const _Way &_W)
{ _W::const_iterator _I; _Itemptr _Lo = Head();
for(_I = _W.rbegin(); _I != _W.rend(); ++_I)
{ if(!(*_I % 2))
_Lo = _Acc::_Right(_Lo);
else
_Lo = _Acc::_Left(_Lo); }
return _Lo; }
void _PtoP(_Point _P, const _Way &_W)
{ while(_P)
{ if((_P % 2))
_P = ((_P - 1) / 2);
else
_P = ((_P - 2) / 2);
_W.push_back(_P); } }
bool _IsValid(_Point _P)
{ _Way _L; _Way::const_iterator _I;
for(_I = _L.begin(); _I != _L.end(); ++_I)
{ if(*_I == _P) return false; }
return true; }
void _Use(_Point _P)
{ _InUse.push_back(_P); }
void _OutUse(_Point _P)
{ _Way _L; _Way::const_iterator _I;
for(_I = _L.begin(); _I != _L.end(); ++_I)
{ if(*_I == _P)
_I.erase(_I); } }
_Itemptr Head()
{ return _Head; }
_Way _InUse;
_A allocator;
_Itemptr _Head;
_Item _Root;
};
#endif
hi, der compiler spuckt folgende fehlermeldungen aus mit denen ich nichts anfangen kann.
--------------------Konfiguration: bintree - Win32 Debug--------------------
Kompilierung läuft...
main.cpp
c:\dokumente und einstellungen\administrator\desktop\fa111\binäre bäume\complex calculator\bintree\bintree.h(127) : error C2059: Syntaxfehler : 'constant'
c:\dokumente und einstellungen\administrator\desktop\fa111\binäre bäume\complex calculator\bintree\bintree.h(190) : Siehe Verweis auf Instantiierung der kompilierten Klassenvorlage 'bintree<_Ty,_A>'
c:\dokumente und einstellungen\administrator\desktop\fa111\binäre bäume\complex calculator\bintree\bintree.h(128) : error C2334: Unerwartete(s) Token vor '{'; sichtbarer Funktionsrumpf wird übersprungen
c:\dokumente und einstellungen\administrator\desktop\fa111\binäre bäume\complex calculator\bintree\bintree.h(190) : Siehe Verweis auf Instantiierung der kompilierten Klassenvorlage 'bintree<_Ty,_A>'
c:\dokumente und einstellungen\administrator\desktop\fa111\binäre bäume\complex calculator\bintree\bintree.h(14) : error C2065: 'allocator' : nichtdeklarierter Bezeichner
c:\dokumente und einstellungen\administrator\desktop\fa111\binäre bäume\complex calculator\bintree\bintree.h(14) : error C2275: "_Ty" : Ungültige Verwendung dieses Typs als Ausdruck
C:\Dokumente und Einstellungen\Administrator\Desktop\fa111\binäre bäume\complex calculator\bintree\main.cpp(11) : Siehe Deklaration von '_Ty'
c:\dokumente und einstellungen\administrator\desktop\fa111\binäre bäume\complex calculator\bintree\bintree.h(14) : error C2974: 'bintree' : Ungueltiges Vorlagenargument für '_A', Typ erwartet
c:\dokumente und einstellungen\administrator\desktop\fa111\binäre bäume\complex calculator\bintree\bintree.h(190) : Siehe Deklaration von 'bintree'
C:\Dokumente und Einstellungen\Administrator\Desktop\fa111\binäre bäume\complex calculator\bintree\main.cpp(11) : error C2143: Syntaxfehler : Fehlendes ';' vor '>'
C:\Dokumente und Einstellungen\Administrator\Desktop\fa111\binäre bäume\complex calculator\bintree\main.cpp(11) : error C2143: Syntaxfehler : Fehlendes ';' vor '>'
Fehler beim Ausführen von cl.exe.
bintree.exe - 7 Fehler, 0 Warnung(en)
ich benutze mvs 6