Using STACK and infix and postfix

  • Thread starter Thread starter Mikeyjoe512
  • Start date Start date
Click For Summary
The discussion centers around the implementation of a stack in C++ for handling infix and postfix notations in mathematical expressions. The user is using DEV C++ and seeks clarification on how to utilize infix and postfix formats, indicating a requirement to convert between these notations. Infix notation is the standard format (e.g., "5 + 8"), while postfix notation, also known as Reverse Polish Notation, rearranges the operators and operands (e.g., "5 8 +"). The conversation suggests that the user may need to write programs for evaluating expressions in both notations using a stack for conversion. Additionally, it is highlighted that the current code example is not aligned with the task, as it deals with names instead of numerical expressions. The goal is to evaluate expressions correctly, with expected outputs for given inputs.
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:
Technology 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.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 1 ·
Replies
1
Views
11K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
11
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 20 ·
Replies
20
Views
5K
Replies
3
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K