Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

recursive java problem

Tags:

java

recursion

Hi i really need your help.First of all , think about we got two text files:

  • numbers.txt
  • process.txt

In numbers.txt we have:

4 5 3 2 10 1 45

In process.txt we have:

+ * /

We want to find 45 as a result with using 4 5 3 2 10 1 numbers and + * / to do sums.

Finally we want a txt file like output.txt 4 + (5 + (3 * (2 + (10/1)))) = 45 include the solution like this.

Each number can be used for one time and each process doesn't needed to be used but we cannot use anyother that not in process.txt.

note:if we cannot find the exact result , we have to find a near value.

Can you please help me about that? I'm totaly lost about this. Sorry for my bad english.

like image 363
club66 Avatar asked Jun 10 '26 13:06

club66


1 Answers

Homework hint: Use two Stacks, one holds numbers, one holds operators. Examine the Stacks when adding operators, to see if you can perform any merging of numbers.

like image 104
Sean Adkinson Avatar answered Jun 13 '26 01:06

Sean Adkinson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!