Jump to content

[Help] MFC maze (Binary Trees)

- - - - -

  • Please log in to reply
12 replies to this topic

#1
Beeko

Beeko

    Learning Programmer

  • Members
  • PipPipPipPip
  • 101 posts
Hey everyone,

I' been working on MFC that takes in a Post Fix Expression and returns the In Fix Expression with full parentheses. I managed to turn the CString into char* and fil lthe Tree with it.
Now I need 2 make a Function called Retrieve that fills the same array with the In Fix Expression, here's and Example:

void Retrieve (char *fix, bintree *r, int pos)

{

   if(!r->RetrieveLeft->IsEmpty())    // This Line is NOT working.

	{

	   fix[pos]=r->RetrieveInfo();

           Retrieve(fix,r->RetrieveLeft,pos++);

	} // I still haven't thought about adding the Parentheses any Ideas?

}

So, thats it, there is still the calculating function, but I'm still not going to work on that now, need 2 finish this Function first.
So any help would be really appreciated.

#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
So what exactly is your problem?
sudo rm -rf /

#3
Beeko

Beeko

    Learning Programmer

  • Members
  • PipPipPipPip
  • 101 posts
cant make this function works

#4
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
You need to be a bit more specific. What happens? Does the program compile, crash, or do you just get the wrong result?
sudo rm -rf /

#5
Beeko

Beeko

    Learning Programmer

  • Members
  • PipPipPipPip
  • 101 posts
if you read the comment you'd find that VS 2010 cant accept it before I run or Debug, it underlins it with red.

#6
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
r->RetrieveLeft()->IsEmpty()
sudo rm -rf /

#7
Beeko

Beeko

    Learning Programmer

  • Members
  • PipPipPipPip
  • 101 posts
I meant Logic wise? is the Function correct? Am I missing something?
It should put the In Fix in the array ex: ((3+5)-6)
and Bec, I'vnt worked on the Parenthesis part I think it would come out 3+5-6, will this Logic works?
And how to make the Parenthesis you think?
if (isOperator(r->RetrieveInfo()))

   fix[pos]='('
?? but how to close the Parenthesis?

#8
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
For infix notation you should have: left, current value, right. And your lack of parenthesis logic will not work if division or multiplication is involved. How are you getting your input data (i.e. what format and from where)?
sudo rm -rf /

#9
Beeko

Beeko

    Learning Programmer

  • Members
  • PipPipPipPip
  • 101 posts
Well I finished the Tree Constructing Fucntion, it works on a similar following Expression : +-369*3 which will turn into (((3-6)+9)*3) Got it? the Parenthesis are just for Illustrating the difference in the +-369 between the 3+6 and the 6-9.

#10
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
In that case, do:

print '('

print lhs

print ')'

print operator

print '('

print rhs

print ')'


sudo rm -rf /

#11
Beeko

Beeko

    Learning Programmer

  • Members
  • PipPipPipPip
  • 101 posts
I think that will just result in a (lhs)operator(rhs) Plus I don't know how long the Expression is going to be.

#12
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
Oops - I meant for something like (x op y). Since complex operations will automatically be surrounded with parentheses, you shouldn't have extraneous things like ((3) + (4))
sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users