Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string>
- using namespace std;
- struct Expressao
- {
- string operando;
- Expressao *next;
- };
- Expressao *topo;
- //inicializa o ponteiro
- void ExpressaoConstrutor()
- {
- topo = NULL;
- }
- bool Empilhar(string novoValor) //ESSA PORRA N TA PEGANDO PQQQQ PQPPP
- {
- Expressao *NovaExpressao;
- NovaExpressao->operando = novoValor;
- NovaExpressao->next = topo;
- topo = NovaExpressao;
- return true;
- }
- string Desempilhar()
- {
- Expressao *temporaria;
- temporaria = topo;
- string valor;
- valor = topo -> operando;
- topo = topo -> next;
- temporaria->next = NULL; //medida de segurança
- free(temporaria);
- return valor;
- }
- void Limpar()
- {
- Expressao *temporaria;
- while(topo != NULL)
- {
- temporaria = topo;
- temporaria->next = NULL;
- topo = topo -> next;
- free(temporaria);
- }
- }
- //Responsável por montar a expressao
- void INF(char operador)
- {
- string novaExpressao;
- if(operador == '^' || operador == 'v' || operador == '>')
- {
- string a = Desempilhar();
- string b = Desempilhar();
- string novaExpressao = "(" + b + operador + a + ")";
- Empilhar(novaExpressao);
- }
- else // -> NEGAÇAO
- {
- string a = Desempilhar();
- string novaExpressao = "(" + operador + a + ")";
- Empilhar(novaExpressao);
- }
- };
- //Responsavel por printar o resultado da expressao
- /*void VAL(char operador)
- {
- }
- */
- int main()
- {
- string a;
- a = "bla";
- cout << Empilhar(a) << endl;
- int qtd;
- cin >> qtd;
- for(int i = 0; i < qtd; i++)
- {
- string act;
- cin >> act;
- string exp;
- cin >> exp;
- for(int i = 0; i < exp.length(); i++)
- {
- if(exp[i] != '1' && exp[i] != '0')
- {
- if(act[0]=='V')
- VAL(exp[i]);
- else
- INF(exp[i]);
- }
- else
- {
- string aux = "";
- aux += exp[i];
- Empilhar(aux);
- }
- }
- }
- cout << topo->operando;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement