|
something like this should do it
int OnlyLeafNodes(Elem *t, int currentDepth=0)
{
if(!t)
return currentDepth;
currentDepth++;
int leftDepth=OnlyLeafNodes(t->left,currentDepth)-currentDepth);
int rightDepth=OnlyLeafNodes(t->right,currentDepth)-currentDepth);
if(max(leftDepth,rightDepth)==1)
cout << t->key << endl;
return currentDepth;
}
I haven't compiled it, sorry, but the general idea is to find all children who only descend one past the currentDepth
|
|
|
|
|
|
sorry
#define max(a,b) a>b?a:b
|
|
|
|
|
Yes I define my own Max function, but why the output is 4,3,1 and not only 4?
|
|
|
|
|
i think the return should be
return currentDepth+(maxDepth,rightdepth);
|
|
|
|
|
maxDepth is? and why is it in brackets? Is it a function or something? i don' t know
|
|
|
|
|
OK I think I did it it has to be
return currentDepth - leftDepth + rightDepth;
|
|
|
|
|
Now If you can explain me how the whole function works...
|
|
|
|
|
it works by only printing those nodes who have only one depth below them, no more
|
|
|
|
|
return currentDepth+max(leftDepth,rightdepth)
|
|
|
|
|
And how to call the function? I mean what has to be the second argument innerDepth. I call it with the tree and the Height as second argument and it gives me 4, 3, 1 as output. I need only 4.
|
|
|
|
|
call it with
OnlyLeafNodes(rootNode,0);
|
|
|
|
|
Hi Everyone,
When i build my newly ported(VS6.0 to 2008) code from VS2008 UI, It builds fine.
When i build it using
MSBuild XXX.sln /t:Clean /p:configuration=Release
MSBuild XXX.sln /l:FileLogger,Microsoft.Build.Engine;logfile=MyLog.log;Build /p:configuration=Release
I get 100's of
nafxcw.lib(winctrl1.obj) : error LNK2005: "public: virtual int __thiscall CStatic::Create(char const *,unsigned long,struct tagRECT const &,class CWnd *,unsigned int)" (?Create@CStatic@@UAEHPBDKABUtagRECT@@PAVCWnd@@I@Z) already defined in mfc90.lib(mfc90.dll)
nafxcw.lib(winctrl1.obj) : error LNK2005: "public: virtual __thiscall CStatic::~CStatic(void)" (??1CStatic@@UAE@XZ) already defined in mfc90.lib(mfc90.dll)
I used the NODEFAULTLIB option in UI. With this option, UI is also failing to build.
If somebody ran into same issue, please advise.
|
|
|
|
|
Hi,
i sometimes get a overflow at runtime when using boost::regex_match...
here's what i'm doing (This code works!):
CString path = "abcd";
boost::regex r("bc");
boost::tmatch what;
if(boost::regex_match(path, what, r))
{
}
else
{
}
When i'm changing the code to
boost::regex r("*bc");
i'll get the error?
I have also tried 'BOOST_REGEX_NON_RECURSIVE' or 'BOOST_REGEX_RECURSIVE'.
Thanks
|
|
|
|
|
boost::tmatch what;
if(boost::regex_match(path, what, r))
Variable what has not been initialized, is this correct?
The best things in life are not things.
|
|
|
|
|
Yes, that's correct.
My code is like the first sample of this link.
|
|
|
|
|
Sorry, but I cannot see anything wrong there. I guess you need to use the debugger and try to trap the error.
The best things in life are not things.
|
|
|
|
|
On a side issue, try to make r static const . The static is particularly important: the regular expression should only be "compiled" once, not every time.
Steve
|
|
|
|
|
Thanks, but that did not matter...
This is the exact error message:
Unhandled exception at 0x7c81eb33 in Hierarchy Explorer.exe: Microsoft C++ exception: boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::regex_error> > at memory location 0x0012ddc4..
|
|
|
|
|
I knew it wouldn't help, it was a side issue. Can you post a small self-contained program that exhibits the problem?
Steve
|
|
|
|
|
Your regular expression isn't valid. What's more, the program is trying to tell you what's wrong. I used the following code:
void Go()
{
try
{
CString path = _T("abcd");
static const boost::tregex r(_T("*bc"));
boost::tmatch what;
if(boost::regex_match(path, what, r))
{
}
else
{
}
}
catch (const boost::regex_error &e)
{
cout << e.what() << endl;
throw;
}
}
The following error is the result:
The repeat operator "*" cannot start a regular expression. The error occured while parsing the regular expression: '>>>HERE>>>*bc'.
The regular expression you're probably after is: .*bc
Steve
|
|
|
|
|
Thats it!
I will have to give the boost syntax more attention... thank you!!
|
|
|
|
|
The syntax isn't boost specific, it's standard regular expression syntax.
Steve
|
|
|
|
|
You're right.
I've played a while with the syntax... you can use it for almost enything!
Actually I have been looking for filter like it is used in SQL queries. I Only wanted to use the *, ?, bracket, AND, OR-statements.
Are regular expressions perhaps a bit too complex for that purpose?
I don't want people to study regular expressions before using my program.
Do you perhaps have a recommendation to me?
|
|
|
|
|
A basic understanding of regular expressions is kind of an must have these days.
Steve
|
|
|
|