Oppure

Loading
02/09/12 16:20
Saik
Salve a tutti.
La seguente funzione mi da diversi problemi in quanto non restituisce il controllo a main, compilo in Visual c++ 2010
Grazie a tutti. Sono disperato:hail::hail:
string expc::converter()
{
	stack<char> temp;
	string result;
	string esp = post;
	int count = 0;
	char current = esp[count];
	temp.push('(');
	esp += ')';
	while(temp.isStackEmpty() == false)
	{	
		count++;
		current = esp[count];
		if(isOperator(current))
		{
			char corrente = current;
			char carattere = temp.pop();
			while(carattere > corrente)
			{
				result += carattere;
				carattere = temp.pop();
			}
			temp.push(carattere);
			temp.push(current);
		}else
		{
			if(current == '(')
			{
				temp.push(current);
			}else{
				if(current == ')')
				{
					char carattere = temp.pop();
					while(carattere != '(')
					{
						result += carattere;
						carattere = temp.pop();
					}
				}else
				{
					result += current;
				}
			}
		}
	}
	return result;
}
aaa
04/09/12 14:53
gigisoft
Salve,

cosi' a occhio, mi sembra una normale funzione, l'unico dubbio e' che forse si trova ad eseguire un ciclo infinito, e che quindi la condizione

(temp.isStackEmpty() == false)

risulti sempre vera.


Ciao.
aaa
05/09/12 13:39
Saik
No ho controllato... Il controllo del programma arriva al result in quanto l'algoritmo funziona benissimo e se viene compilato in g++ funge
aaa
05/09/12 15:47
sarbaturino
Cosa deve risolvere il tuo algoritmo?
aaa
05/09/12 17:19
Saik
l'algoritmo trasforma espressioni dalla notazione infissa a quella postfissa
aaa