private void Converter() { PilhaVetor pilha = new PilhaVetor(1000); // Instancia e inicia a Pilha //Read(Entrada, Simbolo_Lido); // If Not(Simbolo_Lido In ['(',')','+','-','*','/','']) Then //Write(Simbolo_Lido) //Else //Begin //Parar:= false; // While(not parar) and(not umaPilha.estaVazia()) and // (Ha_Precedencia(umaPilha.oTopo(), Simbolo_Lido)) Do // begin //Operador_com_Maior_Precedencia:= umaPilha.desempilhar(); // If operador_com_Maior_Precedencia<> ‘(‘ then // Write(Operador_com_Maior_Precedencia ) // Else // Parar := true; // End; // If Simbolo_Lido<> ')' Then //umaPilha.empilhar(Simbolo_Lido) //Else { fará isso QUANDO o Pilha[TOPO] = '(' } // Operador_com_Maior_Precedencia:= umaPilha.desempilhar(); // End; // End; // While not EOF // While not umaPilha.estaVazia() Do { Descarrega a Pilha Para a Saída } // Begin // Operador_com_Maior_Precedencia := umaPilha.desempilhar(); // If Operador_com_Maior_Precedencia<> '(' Then //Write(Operador_com_Maior_Precedencia); // End; }
private void Atribuir() { lbSequencias.Text = ""; int n = 0; int h = 0; String[] infixa = new String[100]; int unicode; char character; String expressao = txtVisor.Text; PilhaVetor vet = new PilhaVetor(100); PilhaVetor valores = new PilhaVetor(100); PilhaVetor operadores = new PilhaVetor(100); int inicio = 0; for (int i = 0; i < expressao.Length; i++) { int p = 0; while (Char.IsNumber(expressao, h)) { p++; h++; i++; if (h >= expressao.Length) { break; } } vet.empilhar(expressao.Substring(inicio, p)); if (h < expressao.Length) { vet.empilhar(expressao.Substring(h, 1)); } h++; inicio = h; if (h < expressao.Length) { if (!Char.IsNumber(expressao, h)) { vet.empilhar(expressao.Substring(h, 1)); } } else { break; } } int tamanho = vet.tamanho(); for (int i = 0; i < tamanho; i++) { String s = vet.desempilhar().ToString(); if (s.Length == 1) { if (!Char.IsNumber(Convert.ToChar(s))) { operadores.empilhar(s); infixa[i] = operadores.desempilhar().ToString(); } else { valores.empilhar(s); infixa[i] = valores.desempilhar().ToString(); } } else { valores.empilhar(s); infixa[i] = valores.desempilhar().ToString(); } } for (int i = tamanho - 1; i >= 0; i--) { unicode = 65; if (Char.IsNumber(infixa[i], infixa[i].Length - 1)) { unicode += n; character = (char)unicode; lbSequencias.Text += character; n++; } else { lbSequencias.Text += infixa[i]; } } }