Using STACK and infix and postfix

  • Thread starter Thread starter Mikeyjoe512
  • Start date Start date
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
3 replies · 6K views
Mikeyjoe512
Messages
1
Reaction score
0
Mod note: please use [noparse]
Code:
 and
[/noparse] tags around your code, to preserve your indentation and improve readability. I have done this to your code.[/color]

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:
#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:
Physics news on Phys.org
I don't understand what you're asking -
Mikeyjoe512 said:
I have to use infix and postfix in my STACK. The sign is that has to be in infix and post fix is : //

Can you give an example of what you're trying to do?
 
Mikeyjoe512 said:
infix and postfix
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.
 
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.