Professional Documents
Culture Documents
Program Stack Stack Stack Stack
Program Stack Stack Stack Stack
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace Ejercicio4
{
class Program
{
static Stack P = new Stack();
static Stack Q = new Stack();
static string []Cadena=new string[1];
static int Indice=0;
static string ValorAnteror = "+";
if (EsPrecedente(Operador))
{
if(Operando2.Length==1)
Operando1 = Operando1 + Operador + Operando2;
else
Operando1 = Operando1 + Operador +"(" + Operando2 +
")";
}
else
{
Operando1 = Operando1 + Operador + Operando2;
}
ValorAnteror = Operador;
P.Push(Operando1);
}
static bool EsPrecedente(string Operador)
{
if (Operador == "-" && ValorAnteror == "-")
{
return true;
}
if (Operador == "*" && ValorAnteror == "+")
{
return true;
}
if (Operador == "*" && ValorAnteror == "-")
{
return true;
}
return false;
}
static string Invertir()
{
string s = P.Pop().ToString();
string s2 = "";
char r = '1';
for (int k = 0; k < s.Length; k++)
{
r = s[k];
if (r == '(')
r = ')';
else
{
if (r == ')')
r = '(';
}
s2 = r.ToString() + s2;
}
return s2;
}
static void Resolver()
{
while (Indice<Cadena.Length)
{
string Caracter=Cadena[Indice];
while (char.IsDigit(Caracter[0]))
{
P.Push(Caracter);
Indice++;
Caracter = Cadena[Indice];
}
Q.Push(Caracter);
Evaluar();
Indice++;
}
Console.WriteLine(P.Pop().ToString());
}
}
}