# Using STACK and infix and postfix

1. Apr 26, 2012

### Mikeyjoe512

Code (Text):
and

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. Apr 26, 2012

### Staff: Mentor

I don't understand what you're asking -
Can you give an example of what you're trying to do?

3. Apr 27, 2012

### rcgldr

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.

4. Apr 27, 2012

### 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.