#include <stack>
#include <queue>
#include <iostream>
#include <fstream>

using namespace std;


char num[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
char ope[4] = {'+', '-', '*', '/'};

bool isope(char);
bool isnum(char);
int prio(char);
queue<char> ReversePolish();
void write(queue<char> ch);

void main()
{
    queue<char> q;
    q = ReversePolish();
}

bool isope(char c)
{
    int i = 0;
    while ((i < 4)&&(c != ope[i])) 
        ++i;
    if (i < 4) 
        return true;
    else 
        return false;
}

bool isnum(char c)
{
    int i = 0;
    while ((i < 10)&&(c != num[i])) 
        ++i;
    if (i < 10) 
        return true;
    else 
        return false;
}

int prio(char c)
{
    if (c == '$') 
        return 0;
    if ((c == '(')||(c == ')')) 
        return 1;
    else if ((c == '+')||(c == '-')) 
        return 2;
    return 3;
}

queue<char> ReversePolish()
{
    stack<char> stk;
    stk.push('$');
    queue<char> que;
    char ch;

    fstream fin("input.txt", ios::in);
    if (!fin)
    {
        cout << "Khong tim thay file!!" ;
        return que;
    }

    fin >> ch;

    while (ch != '\n')
    {
        if (ch == '(')
            stk.push(ch);
        else if (isnum(ch))
            que.push(ch);
        else if (isope(ch))
        {
            while (stk.top() != '$' && prio(ch) <= prio(stk.top()))
            {
                que.push(stk.top());
                stk.pop();
            }
            stk.push(ch);
        }
        else if (ch == ')')
        {
            while (stk.top() != '(' && (!stk.empty()))
            {
                que.push(stk.top());
                stk.pop();
            }
            stk.pop();
        }
        while (!stk.empty())
        {
            que.push(stk.top());
            stk.pop();
        }
        fin >> ch;
    }
    fin.close();
    return que;
}

Edited 3 Years Ago by Dani: Formatting fixed

#include <stack>
#include <queue>
#include <iostream>
#include <fstream>

using namespace std;


char num[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
char ope[4] = {'+', '-', '*', '/'};

bool isope(char);
bool isnum(char);
int prio(char);
queue<char> ReversePolish();
void write(queue<char> ch);

void main()
{
	queue<char> q;
	q = ReversePolish();
}

bool isope(char c)
{
	int i = 0;
	while ((i < 4)&&(c != ope[i])) 
		++i;
	if (i < 4) 
		return true;
	else 
		return false;
}

bool isnum(char c)
{
	int i = 0;
	while ((i < 10)&&(c != num[i])) 
		++i;
	if (i < 10) 
		return true;
	else 
		return false;
}

int prio(char c)
{
	if (c == '$') 
		return 0;
	if ((c == '(')||(c == ')')) 
		return 1;
	else if ((c == '+')||(c == '-')) 
		return 2;
	return 3;
}

queue<char> ReversePolish()
{
	stack<char> stk;
	stk.push('$');
	queue<char> que;
	char ch;
	
	fstream fin("input.txt", ios::in);
	if (!fin)
	{
		cout << "Khong tim thay file!!" ;
		return que;
	}
	
	fin >> ch;
	
	while (ch != '\n')
	{
		if (ch == '(')
			stk.push(ch);
		else if (isnum(ch))
			que.push(ch);
		else if (isope(ch))
		{
			while (stk.top() != '$' && prio(ch) <= prio(stk.top()))
			{
				que.push(stk.top());
				stk.pop();
			}
			stk.push(ch);
		}
		else if (ch == ')')
		{
			while (stk.top() != '(' && (!stk.empty()))
			{
				que.push(stk.top());
				stk.pop();
			}
			stk.pop();
		}
		while (!stk.empty())
		{
			que.push(stk.top());
			stk.pop();
		}
		fin >> ch;
	}
	fin.close();
	return que;
}

One, it's int main () , not void main () . Two, we need an input file. Three, what's the point of having a program with no output, either to the screen or to a file? How do you test it? If there is output, I missed it. Four, what's the question?

Comments
Four very good questions!
This article has been dead for over six months. Start a new discussion instead.