Hi james, can you please correct me .
Thank you in avdvance.
Hi james, can you please correct me .
Thank you in avdvance.
Sorry, I won't do your homework for youb I will help you do it if you're prepared to put in some brainpower.
If you want to store Strings like "20" in your BST then the data field needs to be a String
not a char
, then that code you have extracting chars from the String isn't needed...
How will you handle on this?
bsto.Insert(new String("5*20"));
bsto.postOrder(bsto.root);
how do i extract those elements in the strings if i will not convert it char ?
You need to parse that into "5" "*" "20"
for that you will need to look at one char at at time, but the numbers need to be put back together.
Hi james, I don't get you what you mean.
Is this what you mean
bsto.Insert("5");
bsto.Insert("*");
bsto.Insert("20");
That's what you probably wan to do, but your code breaks up strings into individual chars, so the 20 gets broken up.
Hi james, but i want the user's to input the infix.I don't want to make it static
You're going to need some sort of parser that can separate numbers and operators
I don't know how to do with the operators...if i will input like this 2*5/9
It's not hard to test each char to see if it's a numeric or an operator
@Hiroshe,
[QUOTE]
Step 1: Parse infix into BST recursively.
Step 2: Write BST in postfix notation.
[/QUOTE]
If i will input infix 5*3/9
,in your step 1 what should i do to the operators?..if 5 is the root what will i do to the next element which is *
where should i will insert this in right or left of the root?
@james,It's not hard to test each char to see if it's a numeric or an operator
,yes we can use the Character.isDigit,but what i my question what should i do if i meet operators where do i insert this.
I have no idea if i encounter operator what should i do?how do i insert this to the tree?
Thank you in advance.
In the case of 5*4/9
I would make a BST that looks like:
"*"
/ \
"5" "/"
/ \
"4" "9"
@Hiroshe,what if there is -,+
,or lets say 5-9*6/3+2
Thank you in advance
uh, you have to learn to think for yourself at some point...
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.