Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Using STACK and infix and postfix

  1. Apr 26, 2012 #1
    Mod note: please use [noparse]
    Code (Text):
     and
    [/noparse] tags around your code, to preserve your indentation and improve readability. I have done this to your code.


    I'm using DEV C++ for my class and I have to use infix and postfix in my STACK. The sign is that has to be in infix and post fix is : //
    Code (Text):

    #include <stdio.h>
    #include <stdlib.h>

    //STACK

    struct node
    {
           char *info;
           node *next;
    };

    node *top;

    void push(node *n)
    {
         if(top == NULL)
         {
                top = n;
                return;
         }
         n->next = top;
         top = n;
    }

    node *pop()
    {
         if(top == NULL) return NULL;
         node *temp;
         temp = top;
         top = top->next;
         return temp;
    }

    bool isEmpty()
    {
         return (top == NULL);
    }

    int main()
    {
        //top = NULL;
       
        //push(new node("Michael"));
        //push(new node("Justin"));
       
        //printf("%s\n", pop()->info);
       
        //push(new node("Saundra"));
        //push(new node("Jerry"));
       
        //while(!isEmpty())
        //{
                        // printf("%s\n", pop()->info);
        //}
       
        system("pause");
        return 0;
    }
     
    Last edited by a moderator: Apr 26, 2012
  2. jcsd
  3. Apr 26, 2012 #2

    Mark44

    Staff: Mentor

    I don't understand what you're asking -
    Can you give an example of what you're trying to do?
     
  4. Apr 27, 2012 #3

    rcgldr

    User Avatar
    Homework Helper

    infix and postfix are two types of notations for mathematical expressions (another type is prefix). Wiki article for infix notation, which is the notation most people normally use:

    http://en.wikipedia.org/wiki/Infix_notation

    postfix notation is also called reverse polish notation, wiki article:

    http://en.wikipedia.org/wiki/Reverse_Polish_notation

    My guess is that you're suppose to parse an string converting infix notation to postfix notation or vice versa, using a stack for the conversion process, or that you're supposed to write two programs to evaluate expressions, one program handles infix notation, the other postfix notation.
     
  5. Apr 27, 2012 #4

    Mark44

    Staff: Mentor

    In addition to what rcgldr said, the commented-out code in what you posted is working with the names of people. Instead it should probably be working with strings that contain numbers and arithmetic operators, with the goal being to evaluate a string such as "5 + 8" (infix) and "5 8 +" (postfix). The result from each of these strings should be 13.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Using STACK and infix and postfix
  1. C++: Postfix to Infix (Replies: 0)

  2. A qustion in stacks (Replies: 3)

Loading...