Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    10
    Rep Power
    0

    Evaluating Prefix Expressions using stack


    So, I have to use a Double stack to evaluate a Prefix Expression. However, I am totally stuck. I have to evaluate numbers that are above 10. So I can't just read the line and reverse the string and then look at each char at a time.

    The Input is something like + * 1 4 34

    Can anyone point me in the right direction
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0
    Originally Posted by akaicewolf
    The Input is something like + * 1 4 34
    I can't write URL. But now, I saw this task!
    Write in google : java Binary expression tree
    First link is for you: *******.ewu.edu
    There are source files.
    If you can, write right solution(or clone link) in this place for progeny.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    10
    Rep Power
    0
    Originally Posted by franktan
    I can't write URL. But now, I saw this task!
    Write in google : java Binary expression tree
    First link is for you: *******.ewu.edu
    There are source files.
    If you can, write right solution(or clone link) in this place for progeny.
    Thanks, but I have to do it using Stacks not trees
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    2
    Rep Power
    0
    Ooh, sorry. I Find Stack in wikipedia: Binary expression tree
    I can't help you more. =(
  8. #5
  9. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,729
    Rep Power
    348
    Do you have the algorithm for processing the tokens as they are read one by one from the input?
    Given the algorithm it should be possible to design and write code to do it.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    10
    Rep Power
    0
    Originally Posted by NormR
    Do you have the algorithm for processing the tokens as they are read one by one from the input?
    Given the algorithm it should be possible to design and write code to do it.
    I am a little bit confused by what you mean. So far I have a Double Stack class but I have no idea how to use it to evaluate the expression.
  12. #7
  13. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,729
    Rep Power
    348
    An algorithm is a list of steps a process/program should take to solve a problem.
    What are the steps your program should take? These steps are not lines of code.
    One of the tools the program will use will be a stack.

    What is a "Double Stack"?
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    10
    Rep Power
    0
    Originally Posted by NormR
    An algorithm is a list of steps a process/program should take to solve a problem.
    What are the steps your program should take? These steps are not lines of code.
    One of the tools the program will use will be a stack.

    What is a "Double Stack"?

    By Double stack, it is a single stack but is is able to store two different sets of things. So the first part of the stack is designed to store operands and the second part is designed to store operators.

    I don't have an algorithm that is what I am trying to figure out. My directions are "Using a Double Stack implement a program that evaluates Prefix expressions". So I am trying to figure out how to go about this.
  16. #9
  17. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,729
    Rep Power
    348
    I don't have an algorithm
    You need to find that before continuing. Do you have an algorithm for solving the problem using any tools?

    Not sure what you mean by parts of a stack: one part for numbers, one part for operators.
    How is that different from two separate stacks: one for numbers, one for operators?

    What is the advantage of a Double Stack?
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    10
    Rep Power
    0
    Originally Posted by NormR
    You need to find that before continuing. Do you have an algorithm for solving the problem using any tools?

    Not sure what you mean by parts of a stack: one part for numbers, one part for operators.
    How is that different from two separate stacks: one for numbers, one for operators?

    What is the advantage of a Double Stack?
    Well that is what I am asking, to help me find an algorithm to solve the problem. If I had the algorithm and the tools I wouldn't need help unless debugging.

    It is not any different then having two separate stacks. I do not know the advantage as the assignment specified using a Double Stack
  20. #11
  21. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,729
    Rep Power
    348
    Have you tried googling for the algorithm?
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    10
    Rep Power
    0
    Originally Posted by NormR
    Have you tried googling for the algorithm?
    Yes. However most of the solutions assume that the input is 1 2 3 + -, instead of - + 1 2 3. Or the other solutions assume that the numbers don't go any higher then 10.

    For instance to solve +-1 23 4. You would start at the end and look at one character at a time until you hit an operator. However, if you look at one character at a time then if the input is +- 1 23 4, the number 23 will be treated it as two separate numbers
  24. #13
  25. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,729
    Rep Power
    348
    solutions assume that the numbers don't go any higher then 10.
    An algorithm would not consider the size of the numbers. You must have been looking at someone's code.
    start at the end and look at one character at a time
    Why not look at one token at a time?

    if you look at one character at a time
    You are trying to write code before you have a design/algorithm. Get the design/algorithm first, then write the code.
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2011
    Posts
    10
    Rep Power
    0
    Originally Posted by NormR
    An algorithm would not consider the size of the numbers. You must have been looking at someone's code.

    Why not look at one token at a time?


    You are trying to write code before you have a design/algorithm. Get the design/algorithm first, then write the code.
    How would I look at one token at a time?
  28. #15
  29. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,729
    Rep Power
    348
    Do you have the algorithm yet?
    You're working on how to code before getting a design.

    There are ways to get tokens from a String. Depends on which end of the String are you starting from?
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo