Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 358
  • Last Modified:

Problem in stack(data structure in C)

How to write a program using stack (in C language)which functions almost like a calculator. the program will receive inputs like for example : 12 * (15 - 6) + 388  
The program will calculate +, -, *, /, (), operations.  
The priority operations are :

   1st. ( )
   2nd. *, /
   3rd. +, -

The program will print the operation for example like The question above :

15 - 6
12 * 9
108 + 388
= 496
0
tagheuer
Asked:
tagheuer
1 Solution
 
baprebapCommented:
refer badrul's query.
0
 
940961slCommented:
I would solve this problem with a recursive function

pseudo code :

double solve (equation)
{
   while ()
      isolate equation between ()   -> start with first ( and  
                                       stop if you have as many (
                                       as )
      solve (equation between () )  -> same function
      substitute result in equation

   while *, /
      isolate equation with * or /
      solve (equation with * or /)
      substitute result in equation

   now you have an equation with only + and - => add (equation)
   return result
}

hope this helps ...

Stefaan
0
 
tagheuerAuthor Commented:
I want more details about the codes.
0
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

 
gjvcCommented:
Do your own homework.
0
 
940961slCommented:
>> I want more details about the codes

Can you be a little bit more specific? What part do you not understand?

Stefaan
0
 
BigRatCommented:
>> Do your own homework.

Quite, but what you need is a Reverse Polish Expression Evaluator. Take virtually any text book and look up Reverse Polish. You usually find the algorithm there. I'm NOT going to hack one in.

   Furthermore you should now give the points away to the first person (Rat excepted) who can tell you the actual NAME of the person after whom the algorithm is called. His name is rarely used since it's almost unpronounceable.
0
 
rbrCommented:
What further problems do you have?
0
 
ozoCommented:
Jan Lukasiewicz
But rather than bother converting to his notation, I'd probably do it with either a recursive descent, or an inside-out evaluator
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The Lifecycle Approach to Managing Security Policy

Managing application connectivity and security policies can be achieved more effectively when following a framework that automates repeatable processes and ensures that the right activities are performed in the right order.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now