943,931 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1353
  • C RSS
Apr 6th, 2006
0

recursion problem

Expand Post »
Well i'm trying to do a calculator program and i'm using recursion to find brackets ( called BracketSearch() ), after finding a "(" i start copying all that is after that in another vector V2 until i find it's corresponding ")".
eg if originally it was

1+2*(3-4*(5/6))-7

then in V2 there will be 3-4*(5/6).

It will recusively pass V2 into BracketSearch() (it will copy the values or operators to V2 and it will also be deleting them from the original vector ) until there are no brackets at all, if there are no brackets at all it will do the calculation and return the value to the previous recursion (return it in the place of the values deleted).

In our example after breaking it down till there are no brackets, there will be only 5/6 left. so it will calculate 5/6 which will give me a double , lets called it num1. So it will return num1 back to it's previous recursion and replace it in the place of (5/6) which will give 3-4*num1.

Then it will calculate 3-4*num1 which will give num2 which in turn will be returned back to it's previous recursion. I want it to keep climbing back to the top till i only have a double as value. Well the problem is that i've been able to devise an algo to break it down till it has no brackets but i don't know how to write a so that it keeps climbing back to the top. How should i return it so that it climbs back to the top??? BracketSearch() must return a double.

Sorry for my poor english i hope you understood what i wanted to say :cheesy:
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tsubasa is offline Offline
6 posts
since Apr 2006
Apr 6th, 2006
0

Re: recursion problem

Use RPN or syntax trees kiddo. :rolleyes:
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: lock commands from c
Next Thread in C Forum Timeline: string problem (IMPORTANT) :((





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC