473,614 Members | 2,352 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

comments on this Binary Searh Tree template?

This is sort of my first attempt at writing a template container class, just
wanted some feedback if everything looks kosher or if there can be any
improvements. This is a template class for a binary search tree. Note there
is a requirement for this to be a Win32/MFC "friendly" class, thus the use
of CObject and POSITION. There is also a requirement for there not to be a
separate iterator class.

template <class TYPE, class ARG_TYPE = const TYPE&> class CBinarySearchTr ee;

template <class TYPE, class ARG_TYPE>
class CBinarySearchTr ee : public CObject
{
// Constructors
public:
CBinarySearchTr ee();
// Attributes
public:
int GetCount() const;
POSITION GetRoot() const;
POSITION GetLeft(POSITIO N& pos) const;
POSITION GetRight(POSITI ON& pos) const;
ARG_TYPE GetElement(POSI TION& pos) const;
// Operations
public:
BOOL Insert(ARG_TYPE newElement);
BOOL Remove(ARG_TYPE element);
void RemoveAll();
POSITION Find(ARG_TYPE element);
// Implementation
public:
virtual ~CBinarySearchT ree();
protected:
struct _TREENODE
{
TYPE element;
_TREENODE* pLeft;
_TREENODE* pRight;
};
protected:
_TREENODE* m_pRoot;
UINT m_nCount;
protected:
BOOL Insert(ARG_TYPE newElement, _TREENODE*& pNode);
BOOL Remove(ARG_TYPE element, _TREENODE*& pNode);
LPVOID FindMin(_TREENO DE* pNode);
};

////////////////////////////////////////////////////////////////////////////
/

template <class TYPE, class ARG_TYPE>
CBinarySearchTr ee<TYPE, ARG_TYPE>::CBin arySearchTree()
{
m_pRoot = NULL;
m_nCount = 0;
}

template <class TYPE, class ARG_TYPE>
CBinarySearchTr ee<TYPE, ARG_TYPE>::~CBi narySearchTree( )
{
RemoveAll();
}

template <class TYPE, class ARG_TYPE>
int CBinarySearchTr ee<TYPE, ARG_TYPE>::GetC ount() const
{
return m_nCount;
}

template <class TYPE, class ARG_TYPE>
POSITION CBinarySearchTr ee<TYPE, ARG_TYPE>::GetR oot() const
{
return (POSITION)m_pRo ot;
}

template <class TYPE, class ARG_TYPE>
POSITION CBinarySearchTr ee<TYPE, ARG_TYPE>::GetL eft(POSITION& pos) const
{
return (POSITION)(((_T REENODE*)pos)->pLeft);
}

template <class TYPE, class ARG_TYPE>
POSITION CBinarySearchTr ee<TYPE, ARG_TYPE>::GetR ight(POSITION& pos) const
{
return (POSITION)(((_T REENODE*)pos)->pRight);
}

template <class TYPE, class ARG_TYPE>
ARG_TYPE CBinarySearchTr ee<TYPE, ARG_TYPE>::GetE lement(POSITION & pos) const
{
return ((_TREENODE*)po s)->element;
}

template <class TYPE, class ARG_TYPE>
BOOL CBinarySearchTr ee<TYPE, ARG_TYPE>::Inse rt(ARG_TYPE newElement)
{
return Insert(newEleme nt, m_pRoot);
}

template <class TYPE, class ARG_TYPE>
BOOL CBinarySearchTr ee<TYPE, ARG_TYPE>::Remo ve(ARG_TYPE element)
{
return Remove(element, m_pRoot);
}

template <class TYPE, class ARG_TYPE>
void CBinarySearchTr ee<TYPE, ARG_TYPE>::Remo veAll()
{
while (m_pRoot != NULL)
Remove(m_pRoot->element);
}

template <class TYPE, class ARG_TYPE>
POSITION CBinarySearchTr ee<TYPE, ARG_TYPE>::Find (ARG_TYPE element)
{
return NULL;
}

template <class TYPE, class ARG_TYPE>
BOOL CBinarySearchTr ee<TYPE, ARG_TYPE>::Inse rt(ARG_TYPE newElement,
_TREENODE*& pNode)
{
if (pNode != NULL)
{
if (newElement < pNode->element)
return Insert(newEleme nt, pNode->pLeft);

if (newElement > pNode->element)
return Insert(newEleme nt, pNode->pRight);
}
else
{
pNode = new _TREENODE;

if (!pNode)
return FALSE;

m_nCount++;

pNode->element = newElement;
pNode->pLeft = NULL;
pNode->pRight = NULL;

return TRUE;
}

return TRUE;
}

template <class TYPE, class ARG_TYPE>
BOOL CBinarySearchTr ee<TYPE, ARG_TYPE>::Remo ve(ARG_TYPE element, _TREENODE*&
pNode)
{
_TREENODE* pTempNode = NULL;

if (!pNode)
return TRUE;

if (element < pNode->element)
{
Remove(element, pNode->pLeft);
}
else if (element > pNode->element)
{
Remove(element, pNode->pRight);
}
else if (pNode->pLeft != NULL && pNode->pRight != NULL)
{
pTempNode = (_TREENODE*)Fin dMin(pNode->pRight);
pNode->element = pTempNode->element;
Remove(element, pNode->pRight);
}
else
{
pTempNode = pNode;

if (m_nCount > 0)

m_nCount--;

if (!pNode->pLeft)
pNode = pNode->pRight;
else if (!pNode->pRight)
pNode = pNode->pLeft;

delete pTempNode;
}

return TRUE;
}

template <class TYPE, class ARG_TYPE>
LPVOID CBinarySearchTr ee<TYPE, ARG_TYPE>::Find Min(_TREENODE* pNode)
{
if (!pNode)
return NULL;
else if (!pNode->pLeft)
return (LPVOID)pNode;

return FindMin(pNode->pLeft);
}
Thanks!


Jul 22 '05 #1
6 2151
Miscellaneous comments below

"Nobody" <no****@cox.net > wrote in message
news:%ZjXb.3347 6$1O.26297@fed1 read05...
This is sort of my first attempt at writing a template container class, just wanted some feedback if everything looks kosher or if there can be any
improvements. This is a template class for a binary search tree. Note there is a requirement for this to be a Win32/MFC "friendly" class, thus the use
of CObject and POSITION. There is also a requirement for there not to be a
separate iterator class.

template <class TYPE, class ARG_TYPE = const TYPE&> class CBinarySearchTr ee;
template <class TYPE, class ARG_TYPE>
class CBinarySearchTr ee : public CObject
{
// Constructors
public:
CBinarySearchTr ee();
// Attributes
public:
int GetCount() const;
POSITION GetRoot() const;
POSITION GetLeft(POSITIO N& pos) const;
POSITION GetRight(POSITI ON& pos) const;
ARG_TYPE GetElement(POSI TION& pos) const;
None of the above three functions modify the pos argument, therefore it
should be

ARG_TYPE GetElement(cons t POSITION& pos) const;

As you have coded it the following is illegal C++

mytree.GetEleme nt(mytree.GetRo ot())

which is a bit of a restriction. As it happens MSVC++ does not enforce this,
but that is MSVC++'s problem, there's still no excuse for using non-const
references where const references are correct.

Also can't you make GetLeft, GetRight and GetElement static? It would make
them very slightly more useable (in the absense of a seperate iterator
class).

// Operations
public:
BOOL Insert(ARG_TYPE newElement);
BOOL Remove(ARG_TYPE element);
bool not BOOL. bool is standard C++, BOOL is not. Try to avoid non-standard
code when there is no good reason for it. (Being more like MFC is not a good
enough reason).
void RemoveAll();
POSITION Find(ARG_TYPE element);
// Implementation
public:
virtual ~CBinarySearchT ree();
protected:
struct _TREENODE
Names with an underscore followed by a capital letter are reserved for
compiler and standard library uses. So _TREENODE is not legal.
{
TYPE element;
_TREENODE* pLeft;
_TREENODE* pRight;
};
protected:
_TREENODE* m_pRoot;
UINT m_nCount;
Ditto unsigned not UINT. Actually probably should be size_t (64 bit
computing is round the corner, size_t will be a 64 bit type when it arrives)
protected:
BOOL Insert(ARG_TYPE newElement, _TREENODE*& pNode);
BOOL Remove(ARG_TYPE element, _TREENODE*& pNode);
LPVOID FindMin(_TREENO DE* pNode);
Ditto, void* not LPVOID.
};
No copy constructor or assignment operator. You can implement these easily
enough using the member functions you have already defined, so why not do
it?

//////////////////////////////////////////////////////////////////////////// /

template <class TYPE, class ARG_TYPE>
CBinarySearchTr ee<TYPE, ARG_TYPE>::CBin arySearchTree()
{
m_pRoot = NULL;
m_nCount = 0;
}

template <class TYPE, class ARG_TYPE>
CBinarySearchTr ee<TYPE, ARG_TYPE>::~CBi narySearchTree( )
{
RemoveAll();
}

template <class TYPE, class ARG_TYPE>
int CBinarySearchTr ee<TYPE, ARG_TYPE>::GetC ount() const
{
return m_nCount;
}

template <class TYPE, class ARG_TYPE>
POSITION CBinarySearchTr ee<TYPE, ARG_TYPE>::GetR oot() const
{
return (POSITION)m_pRo ot;
}

template <class TYPE, class ARG_TYPE>
POSITION CBinarySearchTr ee<TYPE, ARG_TYPE>::GetL eft(POSITION& pos) const
{
return (POSITION)(((_T REENODE*)pos)->pLeft);
}

template <class TYPE, class ARG_TYPE>
POSITION CBinarySearchTr ee<TYPE, ARG_TYPE>::GetR ight(POSITION& pos) const
{
return (POSITION)(((_T REENODE*)pos)->pRight);
}

template <class TYPE, class ARG_TYPE>
ARG_TYPE CBinarySearchTr ee<TYPE, ARG_TYPE>::GetE lement(POSITION & pos) const {
return ((_TREENODE*)po s)->element;
}

template <class TYPE, class ARG_TYPE>
BOOL CBinarySearchTr ee<TYPE, ARG_TYPE>::Inse rt(ARG_TYPE newElement)
{
return Insert(newEleme nt, m_pRoot);
}

template <class TYPE, class ARG_TYPE>
BOOL CBinarySearchTr ee<TYPE, ARG_TYPE>::Remo ve(ARG_TYPE element)
{
return Remove(element, m_pRoot);
}

template <class TYPE, class ARG_TYPE>
void CBinarySearchTr ee<TYPE, ARG_TYPE>::Remo veAll()
{
while (m_pRoot != NULL)
Remove(m_pRoot->element);
}

template <class TYPE, class ARG_TYPE>
POSITION CBinarySearchTr ee<TYPE, ARG_TYPE>::Find (ARG_TYPE element)
{
Huh?
return NULL;
}

template <class TYPE, class ARG_TYPE>
BOOL CBinarySearchTr ee<TYPE, ARG_TYPE>::Inse rt(ARG_TYPE newElement,
_TREENODE*& pNode)
I'd like to see this function return true if an element was inserted and
false if you attempt to insert a duplicate element, and a exception thrown
for the out of memory error.

This code is not exception safe, but I guess you aren't too worried about
that.
{
if (pNode != NULL)
{
if (newElement < pNode->element)
return Insert(newEleme nt, pNode->pLeft);

if (newElement > pNode->element)
return Insert(newEleme nt, pNode->pRight);
}
else
{
pNode = new _TREENODE;

if (!pNode)
return FALSE;
More MCVC++ specific code. new does return NULL on memory exhaustion in
standard C++, it throws an exception instead.

m_nCount++;

pNode->element = newElement;
pNode->pLeft = NULL;
pNode->pRight = NULL;
I think the above is better written like this
_TREENODE* tmp;
tmp = new _TREENODE(newEl ement);
if (tmp == 0) // MSVC++ specific code, new can return NULL in MSVC++
throw std::bad_alloc( ); // do the right thing on memory
exhaustion
pNode = tmp;
++m_nCount;

You'll have to add the constructor for _TREENODE.

This code has two points, it does the correct thing on memory exhaustion,
and it is exception safe, i.e. if either you run out of memory, or if
copying the newElement throws an exception then your tree is left unchanged,
that is not the case with your current code.

return TRUE;
}

return TRUE;
}

template <class TYPE, class ARG_TYPE>
BOOL CBinarySearchTr ee<TYPE, ARG_TYPE>::Remo ve(ARG_TYPE element, _TREENODE*& pNode)
{
_TREENODE* pTempNode = NULL;

if (!pNode)
return TRUE;

if (element < pNode->element)
{
Remove(element, pNode->pLeft);
}
else if (element > pNode->element)
{
Remove(element, pNode->pRight);
}
else if (pNode->pLeft != NULL && pNode->pRight != NULL)
{
pTempNode = (_TREENODE*)Fin dMin(pNode->pRight);
pNode->element = pTempNode->element;
Remove(element, pNode->pRight);
}
else
{
pTempNode = pNode;

if (m_nCount > 0)

m_nCount--;

if (!pNode->pLeft)
pNode = pNode->pRight;
else if (!pNode->pRight)
pNode = pNode->pLeft;

delete pTempNode;
}

return TRUE;
}

template <class TYPE, class ARG_TYPE>
LPVOID CBinarySearchTr ee<TYPE, ARG_TYPE>::Find Min(_TREENODE* pNode)
{
if (!pNode)
return NULL;
else if (!pNode->pLeft)
return (LPVOID)pNode;

return FindMin(pNode->pLeft);
}
Thanks!


john
Jul 22 '05 #2
>
No copy constructor or assignment operator. You can implement these easily
enough using the member functions you have already defined, so why not do
it?


Actually scratch that. A copy ctor written that way would not be efficient.
You should use a straightforward recursive tree copy instead.

john
Jul 22 '05 #3
Thanks for the feedback John. Some good technical points here that I will
modify my code for and some style issues that are "to each his own" :).

Ooops, in the code posted, the Find function was not implemented.

Why make the GetElement, GetLeft and GetRight static? I understand they
operate on the node struct and not the tree itself, but does it add anything
to be static?

If those methods were static, wouldn't I have to call them with some ugly
code like:

CBinarySearchTr ee<int>::GetLef t(pos);

or something of that nature? vs.

tree.GetLeft(po s);

I have always followed the belief of not making class functions or members
static. If a member function is static, it probably shouldn't be a member
function.

Yes, I do need to implement a copy constructor as well.

Again, thanks for the feedback, much appreciated.

"John Harrison" <jo************ *@hotmail.com> wrote in message
news:c0******** *****@ID-196037.news.uni-berlin.de...
Miscellaneous comments below

"Nobody" <no****@cox.net > wrote in message
news:%ZjXb.3347 6$1O.26297@fed1 read05...
This is sort of my first attempt at writing a template container class, just
wanted some feedback if everything looks kosher or if there can be any
improvements. This is a template class for a binary search tree. Note

there
is a requirement for this to be a Win32/MFC "friendly" class, thus the use of CObject and POSITION. There is also a requirement for there not to be a separate iterator class.

template <class TYPE, class ARG_TYPE = const TYPE&> class

CBinarySearchTr ee;

template <class TYPE, class ARG_TYPE>
class CBinarySearchTr ee : public CObject
{
// Constructors
public:
CBinarySearchTr ee();
// Attributes
public:
int GetCount() const;
POSITION GetRoot() const;
POSITION GetLeft(POSITIO N& pos) const;
POSITION GetRight(POSITI ON& pos) const;
ARG_TYPE GetElement(POSI TION& pos) const;


None of the above three functions modify the pos argument, therefore it
should be

ARG_TYPE GetElement(cons t POSITION& pos) const;

As you have coded it the following is illegal C++

mytree.GetEleme nt(mytree.GetRo ot())

which is a bit of a restriction. As it happens MSVC++ does not enforce

this, but that is MSVC++'s problem, there's still no excuse for using non-const
references where const references are correct.

Also can't you make GetLeft, GetRight and GetElement static? It would make
them very slightly more useable (in the absense of a seperate iterator
class).

// Operations
public:
BOOL Insert(ARG_TYPE newElement);
BOOL Remove(ARG_TYPE element);
bool not BOOL. bool is standard C++, BOOL is not. Try to avoid

non-standard code when there is no good reason for it. (Being more like MFC is not a good enough reason).
void RemoveAll();
POSITION Find(ARG_TYPE element);
// Implementation
public:
virtual ~CBinarySearchT ree();
protected:
struct _TREENODE
Names with an underscore followed by a capital letter are reserved for
compiler and standard library uses. So _TREENODE is not legal.
{
TYPE element;
_TREENODE* pLeft;
_TREENODE* pRight;
};
protected:
_TREENODE* m_pRoot;
UINT m_nCount;


Ditto unsigned not UINT. Actually probably should be size_t (64 bit
computing is round the corner, size_t will be a 64 bit type when it

arrives)
protected:
BOOL Insert(ARG_TYPE newElement, _TREENODE*& pNode);
BOOL Remove(ARG_TYPE element, _TREENODE*& pNode);
LPVOID FindMin(_TREENO DE* pNode);
Ditto, void* not LPVOID.
};


No copy constructor or assignment operator. You can implement these easily
enough using the member functions you have already defined, so why not do
it?

////////////////////////////////////////////////////////////////////////////
/

template <class TYPE, class ARG_TYPE>
CBinarySearchTr ee<TYPE, ARG_TYPE>::CBin arySearchTree()
{
m_pRoot = NULL;
m_nCount = 0;
}

template <class TYPE, class ARG_TYPE>
CBinarySearchTr ee<TYPE, ARG_TYPE>::~CBi narySearchTree( )
{
RemoveAll();
}

template <class TYPE, class ARG_TYPE>
int CBinarySearchTr ee<TYPE, ARG_TYPE>::GetC ount() const
{
return m_nCount;
}

template <class TYPE, class ARG_TYPE>
POSITION CBinarySearchTr ee<TYPE, ARG_TYPE>::GetR oot() const
{
return (POSITION)m_pRo ot;
}

template <class TYPE, class ARG_TYPE>
POSITION CBinarySearchTr ee<TYPE, ARG_TYPE>::GetL eft(POSITION& pos) const
{
return (POSITION)(((_T REENODE*)pos)->pLeft);
}

template <class TYPE, class ARG_TYPE>
POSITION CBinarySearchTr ee<TYPE, ARG_TYPE>::GetR ight(POSITION& pos) const {
return (POSITION)(((_T REENODE*)pos)->pRight);
}

template <class TYPE, class ARG_TYPE>
ARG_TYPE CBinarySearchTr ee<TYPE, ARG_TYPE>::GetE lement(POSITION & pos)

const
{
return ((_TREENODE*)po s)->element;
}

template <class TYPE, class ARG_TYPE>
BOOL CBinarySearchTr ee<TYPE, ARG_TYPE>::Inse rt(ARG_TYPE newElement)
{
return Insert(newEleme nt, m_pRoot);
}

template <class TYPE, class ARG_TYPE>
BOOL CBinarySearchTr ee<TYPE, ARG_TYPE>::Remo ve(ARG_TYPE element)
{
return Remove(element, m_pRoot);
}

template <class TYPE, class ARG_TYPE>
void CBinarySearchTr ee<TYPE, ARG_TYPE>::Remo veAll()
{
while (m_pRoot != NULL)
Remove(m_pRoot->element);
}

template <class TYPE, class ARG_TYPE>
POSITION CBinarySearchTr ee<TYPE, ARG_TYPE>::Find (ARG_TYPE element)
{


Huh?
return NULL;
}

template <class TYPE, class ARG_TYPE>
BOOL CBinarySearchTr ee<TYPE, ARG_TYPE>::Inse rt(ARG_TYPE newElement,
_TREENODE*& pNode)


I'd like to see this function return true if an element was inserted and
false if you attempt to insert a duplicate element, and a exception thrown
for the out of memory error.

This code is not exception safe, but I guess you aren't too worried about
that.
{
if (pNode != NULL)
{
if (newElement < pNode->element)
return Insert(newEleme nt, pNode->pLeft);

if (newElement > pNode->element)
return Insert(newEleme nt, pNode->pRight);
}
else
{
pNode = new _TREENODE;

if (!pNode)
return FALSE;


More MCVC++ specific code. new does return NULL on memory exhaustion in
standard C++, it throws an exception instead.

m_nCount++;

pNode->element = newElement;
pNode->pLeft = NULL;
pNode->pRight = NULL;


I think the above is better written like this
_TREENODE* tmp;
tmp = new _TREENODE(newEl ement);
if (tmp == 0) // MSVC++ specific code, new can return NULL in

MSVC++ throw std::bad_alloc( ); // do the right thing on memory
exhaustion
pNode = tmp;
++m_nCount;

You'll have to add the constructor for _TREENODE.

This code has two points, it does the correct thing on memory exhaustion,
and it is exception safe, i.e. if either you run out of memory, or if
copying the newElement throws an exception then your tree is left unchanged, that is not the case with your current code.

return TRUE;
}

return TRUE;
}

template <class TYPE, class ARG_TYPE>
BOOL CBinarySearchTr ee<TYPE, ARG_TYPE>::Remo ve(ARG_TYPE element,

_TREENODE*&
pNode)
{
_TREENODE* pTempNode = NULL;

if (!pNode)
return TRUE;

if (element < pNode->element)
{
Remove(element, pNode->pLeft);
}
else if (element > pNode->element)
{
Remove(element, pNode->pRight);
}
else if (pNode->pLeft != NULL && pNode->pRight != NULL)
{
pTempNode = (_TREENODE*)Fin dMin(pNode->pRight);
pNode->element = pTempNode->element;
Remove(element, pNode->pRight);
}
else
{
pTempNode = pNode;

if (m_nCount > 0)

m_nCount--;

if (!pNode->pLeft)
pNode = pNode->pRight;
else if (!pNode->pRight)
pNode = pNode->pLeft;

delete pTempNode;
}

return TRUE;
}

template <class TYPE, class ARG_TYPE>
LPVOID CBinarySearchTr ee<TYPE, ARG_TYPE>::Find Min(_TREENODE* pNode)
{
if (!pNode)
return NULL;
else if (!pNode->pLeft)
return (LPVOID)pNode;

return FindMin(pNode->pLeft);
}
Thanks!


john

Jul 22 '05 #4

"Nobody" <no****@cox.net > wrote in message
news:0hlXb.3348 1$1O.1549@fed1r ead05...
Thanks for the feedback John. Some good technical points here that I will
modify my code for and some style issues that are "to each his own" :).

Ooops, in the code posted, the Find function was not implemented.

Why make the GetElement, GetLeft and GetRight static? I understand they
operate on the node struct and not the tree itself, but does it add anything to be static?

If those methods were static, wouldn't I have to call them with some ugly
code like:

CBinarySearchTr ee<int>::GetLef t(pos);

or something of that nature? vs.

tree.GetLeft(po s);

No, you can use EITHER syntax if the function is static. The point of making
them static is that you can do node iteration without having the original
tree.
I have always followed the belief of not making class functions or members
static. If a member function is static, it probably shouldn't be a member
function.
Fair enough, although I wouldn't be as categorical as you are being. But in
this case these three functions should be part of a seperate iterator class,
but you've already ruled that out, so I thought making them static is the
next best thing.

It's going to get very tedious when writing functions that use GetLeft,
GetRight and GetElement to always have to pass the tree itself to that
function as well.

Yes, I do need to implement a copy constructor as well.

Again, thanks for the feedback, much appreciated.


john
Jul 22 '05 #5
John Harrison wrote:
Miscellaneous comments below

"Nobody" <no****@cox.net > wrote in message
news:%ZjXb.3347 6$1O.26297@fed1 read05...
{
TYPE element;
_TREENODE* pLeft;
_TREENODE* pRight;
};
protected:
_TREENODE* m_pRoot;
UINT m_nCount;


Ditto unsigned not UINT. Actually probably should be size_t (64 bit
computing is round the corner, size_t will be a 64 bit type when it arrives)


I noticed the following comment in gc.h from Hans Boehm's garbage
collector: "[size_t] and [ptr_diff_t] appear to have incorrect
definitions on many systems. Notably 'typedef int size_t' seems to be
both frequent and WRONG." Comments?
Jul 22 '05 #6

"Jon Willeke" <j.***********@ verizon.dot.net > wrote in message
news:qN******** *********@nwrdn y02.gnilink.net ...
John Harrison wrote:
Miscellaneous comments below

"Nobody" <no****@cox.net > wrote in message
news:%ZjXb.3347 6$1O.26297@fed1 read05...
{
TYPE element;
_TREENODE* pLeft;
_TREENODE* pRight;
};
protected:
_TREENODE* m_pRoot;
UINT m_nCount;
Ditto unsigned not UINT. Actually probably should be size_t (64 bit
computing is round the corner, size_t will be a 64 bit type when it

arrives)
I noticed the following comment in gc.h from Hans Boehm's garbage
collector: "[size_t] and [ptr_diff_t] appear to have incorrect
definitions on many systems. Notably 'typedef int size_t' seems to be
both frequent and WRONG." Comments?


I believe the standard requires size_t to be an unsigned integral type. Hans
Boehm's garbage collector is very old. I doubt that many compilers get
size_t wrong nowadays.

john
Jul 22 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3398
by: Jerry Khoo | last post by:
hello, everybody, i am kinda new here, nice to meet u all. Now, i am > cs students and are now facing difficult problems in understanding > what a binary tree is, how it works, and the algorithm to display, > arrange, find, delete the leaf node in binary tree. > > I hope that anyone with expereince in building binary tree could help > me in explaining the binary tree functions, and give a sample code of > the whole picture behind the...
8
2768
by: Jerry Khoo | last post by:
hello, everybody, i am kinda new here, nice to meet u all. Now, i am cs students and are now facing difficult problems in understanding what a binary tree is, how it works, and the algorithm to display, arrange, find, delete the leaf node in binary tree. I hope that anyone with expereince in building binary tree could help me in explaining the binary tree functions, and give a sample code of the whole picture behind the tree. And...
0
5214
by: Reed | last post by:
Can someone stear me in the right direction to convert a binary tree from a Linked List to a Dynamic Array... Dynamic arrays aren't something im strong with. //********bintree.h******** #ifndef BINTREE_H #define BINTREE_H #include <cstdlib> // Provides NULL and size_t
4
3887
by: mathon | last post by:
Hello, im currently implementing a binary search tree means, that a greater number than root will be added as right child and a less number as left child. My insert function looks currently like this: template <class Item> void bag<Item>::insert(const Item& entry) // Header file used: bintree.h
1
2930
by: hn.ft.pris | last post by:
I have the following code: Tree.h defines a simple binary search tree node structure ########## FILE Tree.h ################ #ifndef TREE_H #define TREE_H //using namespace std; template <typename Tclass Tree{ private: Tree<T*left;
4
11005
by: whitehatmiracle | last post by:
Hello I have written a program for a binary tree. On compiling one has to first chose option 1 and then delete or search. Im having some trouble with the balancing function. It seems to be going into an infinite loop, i think im messing up with the pointers. Heres the code. //press 1, first, Do not press it a second time!!!
8
3286
by: n.noumia | last post by:
- with 10 nodes, give one example of an unbalanced binary tree and one example of a balanced binary tree - what is the advantage of having a balanced binary tree over an unbalanced tree? - number your nodes, then give the order in which nodes will be visited by a depth-first-search - explain the differences between traversing the tree pre-order, in- order and post-order
11
1191
by: Defected | last post by:
Hi, How i can create a Binary Search Tree with a class ? thanks
6
20009
by: APEJMAN | last post by:
would you please help me? I wrote 3 separate line of code for printing my binary tree, and now I am trying to print the level-order traversal of the tree, where the nodes at each level of the tree are printed on a separate line. my codes are below,( for printing inorder, preorder and post order) I have no Idea how I can print them in , level-order traversal I think I should use a Queue, but how? do you have any code that can help me? would...
0
8198
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8591
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8294
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8444
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7115
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6093
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4138
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2575
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.