Thread: stacks

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    1

    stacks

    The task is to produce a working program to accept a set of instructions and to execute them on a stack and to output the result of the expression. The set of instrtuctions is to be held in an array that ideally should be loaded from a file. Validation of the set of input instructions is not required as we assume the set of intsructions have been produced by a translater.

    note: Any postfix expression will consist of literal values and the four operators + - * and /.

    Example:
    For the infix expression: 2.4+6.37*4.9 the translater will generate:
    load 2.4
    load 6.37
    load 4.9
    apply *
    apply +

    This code will be evaluated on a stack computer as follows:
    Instruction Stack
    load 2.4 2.4
    load 6.37 2.4 6.37
    load 4.9 4.9
    apply * 2.4 31.213
    apply + 33.613
    stop (This will cause 33.613 to be output)

    Does anyone have any ideas for the coding?
    Any help much appreciated

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,823
    > Does anyone have any ideas for the coding?

    Sure do. This is best solved using an advanced data structure commonly called a "stack", which utilizes a FILO design to store data. More information can be found in YOUR TEXTBOOK or ON THE FSCKING WEB!

  3. #3
    Black Mage Extraordinaire VegasSte's Avatar
    Join Date
    Oct 2002
    Posts
    167
    Do it yourself or you will learn nothing

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please Help Me With This Code Of Implementing Stacks
    By raghu_equinox in forum C Programming
    Replies: 3
    Last Post: 10-19-2006, 07:22 AM
  2. ...multiplication using stacks
    By iiwhitexb0iii in forum C Programming
    Replies: 1
    Last Post: 10-09-2006, 01:28 AM
  3. Avioding Stacks
    By LoafOfBread34 in forum C++ Programming
    Replies: 8
    Last Post: 12-08-2004, 06:20 AM
  4. Dumping singly linked list into 2 stacks.
    By strotee76 in forum C++ Programming
    Replies: 5
    Last Post: 05-16-2004, 05:48 PM
  5. Stacks stacks stacks
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 06-06-2002, 02:01 AM