Anyone explain me this thing .. I'l b thankful .. [modified]
-
template < class type > class binarytree { public: struct treenode { int element; treenode *left, *right; treenode() : left(0), right(0) {} treenode(int item, treenode *leftnode=0, treenode *rightnode=0):element(item), left(leftnode), right(rightnode){} }; protected: treenode *root; BOOL insert(treenode *&tree, const type& item); .... }; template < class type > BOOL binarytree::insert(treenode* &tree, const type& item) { if ( tree==0 ) { tree=new treenode(item); return tree ? TRUE : FALSE; } else if (item < tree->element ) return insert(tree->left, item); else return insert (tree->right, item); } :confused: what is thing "BOOL" in this code ?? how can a function return TRUE, FALSE or a node of type treenode at same time. If anyone can clear me this thing BOOL, FALSE, TRUE .. I'l b thankful ... -- modified at 13:18 Thursday 7th December, 2006
-
template < class type > class binarytree { public: struct treenode { int element; treenode *left, *right; treenode() : left(0), right(0) {} treenode(int item, treenode *leftnode=0, treenode *rightnode=0):element(item), left(leftnode), right(rightnode){} }; protected: treenode *root; BOOL insert(treenode *&tree, const type& item); .... }; template < class type > BOOL binarytree::insert(treenode* &tree, const type& item) { if ( tree==0 ) { tree=new treenode(item); return tree ? TRUE : FALSE; } else if (item < tree->element ) return insert(tree->left, item); else return insert (tree->right, item); } :confused: what is thing "BOOL" in this code ?? how can a function return TRUE, FALSE or a node of type treenode at same time. If anyone can clear me this thing BOOL, FALSE, TRUE .. I'l b thankful ... -- modified at 13:18 Thursday 7th December, 2006
Pimra wrote:
what is thing "BOOL" in this code ??
It's the type that's returned from the
insert()
method. It usually evaluates to 0 and 1.Pimra wrote:
how can a function return...a node of type treenode at same time.
It's not.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
Pimra wrote:
what is thing "BOOL" in this code ??
It's the type that's returned from the
insert()
method. It usually evaluates to 0 and 1.Pimra wrote:
how can a function return...a node of type treenode at same time.
It's not.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
But when i write this code in my compiler that is microsft visual C++ 6.0 it gives error of undeclared identifier .. true=1, false=0 but this is in caps .. TRUE and FALSE also tht data type is bool not BOOL .. this caps thing gives eror and if replaced by smalls it gives eror for return types .. i simply cant understand this code .. Sir, if u plz take out little time from ur precious time and try 2 explain a little more , I'l b vry thankful ..
-
But when i write this code in my compiler that is microsft visual C++ 6.0 it gives error of undeclared identifier .. true=1, false=0 but this is in caps .. TRUE and FALSE also tht data type is bool not BOOL .. this caps thing gives eror and if replaced by smalls it gives eror for return types .. i simply cant understand this code .. Sir, if u plz take out little time from ur precious time and try 2 explain a little more , I'l b vry thankful ..
the
BOOL
type is eitherTRUE
orFALSE
and thebool
type is eithertrue
orfalse
Maximilien Lincourt Your Head A Splode - Strong Bad
-
But when i write this code in my compiler that is microsft visual C++ 6.0 it gives error of undeclared identifier .. true=1, false=0 but this is in caps .. TRUE and FALSE also tht data type is bool not BOOL .. this caps thing gives eror and if replaced by smalls it gives eror for return types .. i simply cant understand this code .. Sir, if u plz take out little time from ur precious time and try 2 explain a little more , I'l b vry thankful ..
Pimra wrote:
true=1, false=0
true
andfalse
are already defined.Pimra wrote:
...this caps thing gives eror...
Because
TRUE
andFALSE
have not been defined.
"Approved Workmen Are Not Ashamed" - 2 Timothy 2:15
"Judge not by the eye but by the heart." - Native American Proverb
-
template < class type > class binarytree { public: struct treenode { int element; treenode *left, *right; treenode() : left(0), right(0) {} treenode(int item, treenode *leftnode=0, treenode *rightnode=0):element(item), left(leftnode), right(rightnode){} }; protected: treenode *root; BOOL insert(treenode *&tree, const type& item); .... }; template < class type > BOOL binarytree::insert(treenode* &tree, const type& item) { if ( tree==0 ) { tree=new treenode(item); return tree ? TRUE : FALSE; } else if (item < tree->element ) return insert(tree->left, item); else return insert (tree->right, item); } :confused: what is thing "BOOL" in this code ?? how can a function return TRUE, FALSE or a node of type treenode at same time. If anyone can clear me this thing BOOL, FALSE, TRUE .. I'l b thankful ... -- modified at 13:18 Thursday 7th December, 2006
1. Sounds like the conditional expression syntax is confusing you.
return tree ? TRUE : FALSE;
is equivalent to
if (tree != NULL)
return TRUE;
else
return FALSE;2. A long time ago, in a time now forgotten, the data type bool and it's associated constants of true and false had not been created. Microsoft wanted a boolean type for use in their Windows code, so they created one and named it 'BOOL'. It was created using a typedef statement. BOOL has associated constants of TRUE and FALSE that are defined using the C-Preprocessor macro facility (in other words, #define). Much code was written using BOOL, TRUE and FALSE. Some time later, the ANSI committee got around to adding bool to the language as a native type (that is exactly one byte in size). Alas, the Windows code base, which used BOOL, was now quite large. It was a bigger pain to change to use bool than not to change, so BOOL was kept. So we have the legacy in Windows C++ code of seeing both BOOL and bool used. In order for BOOL to work, the proper headers must be included in the file. The definitions live in <WinDef.h> but if you just include <windows.h> ( or "stdafx.h" if you are using MFC ) before the template definition, the template code will have these values defined. Dan
Be clear about the difference between your role as a programmer and as a tester. The tester in you must be suspicious, uncompromising, hostile, and compulsively obsessed with destroying, utterly destroying, the programmer's software. ----- Boris Beizer
-
1. Sounds like the conditional expression syntax is confusing you.
return tree ? TRUE : FALSE;
is equivalent to
if (tree != NULL)
return TRUE;
else
return FALSE;2. A long time ago, in a time now forgotten, the data type bool and it's associated constants of true and false had not been created. Microsoft wanted a boolean type for use in their Windows code, so they created one and named it 'BOOL'. It was created using a typedef statement. BOOL has associated constants of TRUE and FALSE that are defined using the C-Preprocessor macro facility (in other words, #define). Much code was written using BOOL, TRUE and FALSE. Some time later, the ANSI committee got around to adding bool to the language as a native type (that is exactly one byte in size). Alas, the Windows code base, which used BOOL, was now quite large. It was a bigger pain to change to use bool than not to change, so BOOL was kept. So we have the legacy in Windows C++ code of seeing both BOOL and bool used. In order for BOOL to work, the proper headers must be included in the file. The definitions live in <WinDef.h> but if you just include <windows.h> ( or "stdafx.h" if you are using MFC ) before the template definition, the template code will have these values defined. Dan
Be clear about the difference between your role as a programmer and as a tester. The tester in you must be suspicious, uncompromising, hostile, and compulsively obsessed with destroying, utterly destroying, the programmer's software. ----- Boris Beizer
Gave you a 5 for the "tale of the BOOL". :)
- S 50 cups of coffee and you know it's on!