Using STACK and infix and postfix

  • Thread starter Thread starter Mikeyjoe512
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around the implementation of infix and postfix notations using a stack in C++. Participants are exploring how to convert and evaluate mathematical expressions represented in these notations, as well as clarifying the requirements of the task.

Discussion Character

  • Exploratory
  • Technical explanation
  • Conceptual clarification
  • Homework-related

Main Points Raised

  • One participant shares a code snippet for a stack implementation in C++, indicating the need to work with infix and postfix notations.
  • Another participant expresses confusion about the original poster's request and asks for clarification or examples of the intended functionality.
  • A third participant provides background information on infix and postfix notations, suggesting that the task may involve parsing strings to convert between these notations using a stack.
  • A later reply suggests that the code should focus on evaluating arithmetic expressions rather than names, proposing an example of evaluating "5 + 8" in infix and "5 8 +" in postfix, with the expected result being 13.

Areas of Agreement / Disagreement

Participants do not appear to have reached a consensus on the specific requirements of the task, and there are multiple interpretations of how to implement the infix and postfix functionality.

Contextual Notes

There are limitations in the clarity of the original request, as well as assumptions about the types of expressions to be handled (e.g., names versus arithmetic expressions). The discussion does not resolve these ambiguities.

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.
 

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