infix to postfix conversion

edit-using array based stack class
So i am having a problem, i do not understand how to convert an infix notation into a postfix notation from a txt file. The infix expressions are stored in a text file

for example inside the text file is

6+9
2+7*8
(1+5)*3
5+(6-2)*((2-8)

at the moment my header file is

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifndef STACKS_H
#define STACKS_H
#include <iostream>
using namespace std;



const int STACKS_CAPACITY = 128;
typedef int StacksElement;

class Stacks

{
	private:

		StacksElement myArray[STACKS_CAPACITY];
		int myTop;

	public:
		
		Stacks();
		void push(const StacksElement & value);
		void pop();
		bool empty() const;
		void display(ostream & out) const;
		StacksElement top() const;



};

inline Stacks::Stacks()
{
	myTop = -1;
}



inline bool Stacks::empty() const
{
	return (myTop == -1);
}




inline void Stacks::pop()
{
	 if(myTop >= 0)
		myTop--;
	 else    
		 cerr << "*** Stack is empty -- "            "can't remove a value ***\n";

}


void Stacks::push(const StacksElement & value)
{
	if (myTop < STACKS_CAPACITY - 1)
	{			
		++myTop;
		myArray[myTop] = value;
	}
	else   cerr <<     "*** Stack full -- can't add new value ***\n"    "Must increase value of STACK_CAPACITY in Stack.h\n";
}


inline void Stacks::display(ostream & out) const
{  for (int i = myTop; i >= 0; i--) 
	    out << myArray[i] << endl;
} 


StacksElement Stacks::top() const
{
  if (myTop >= 0)   
  return (myArray[myTop]);
  else  
  {    cerr << "*** Stack is empty "            " -- returning garbage ***\n";   
  return myArray[STACKS_CAPACITY-1];  
  }
} 
#endif 



and my test client cpp is
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
using namespace std;
#include "Stacks.h"
#include <fstream>
#include <string>






int main()
	
{

cout << "The current infix expressions are: " << endl;

 string getcontent;
    ifstream openfile ("infix.txt");
    if(openfile.is_open())
    {
        while(! openfile.eof())
        {
            openfile >> getcontent;
            cout << getcontent << endl;
        }
    }

cout << "Now to convert into post-fix expression and compute the result: " << endl;

cin.get();
cin.get();
return 0;

}


but from here i have no idea how to make it convert the into postfix, any any all help greatly appreciated
Last edited on
anybody at all?
This site has a pretty good explanation of it. http://scriptasylum.com/tutorials/infix_postfix/algorithms/infix-postfix/
i read it but i am still confused on how to implement the code however
Topic archived. No new replies allowed.