Ir para conteúdo
Fórum Script Brasil

copynow

Membros
  • Total de itens

    3
  • Registro em

  • Última visita

Sobre copynow

copynow's Achievements

0

Reputação

  1. Implementar a função “paint bucket” 2 – Implementar a função “paint bucket” Entrada: uma matriz mxn com “x” ou “.” em cada elemento. Exemplo: x . . . . . x x . . . . x . . x x . . . . . . . . Saída: uma matriz “alterada”. Exemplo: x . . . . x x x . . x x x . . x x x x x x x x x x Utilizar entrada e saída de arquivos texto, já tenho a Pilha.h Preciso de ajuda para implementar o main: #ifndef _PilhaEnc_H #define _PilhaEnc_H #include <stdexcept> using std::logic_error; namespace ED { template <typename Tipo> class PilhaEnc { public: PilhaEnc(); ~PilhaEnc(); // Métodos principais void empilha(const Tipo &elem) throw (logic_error); Tipo desempilha() throw (logic_error); // Métodos auxiliares bool vazia(); int tamanho(); private: struct Celula { Tipo el; Celula *prox; }; Celula *topo; int nelem; }; // Construtor template <typename Tipo> PilhaEnc<Tipo>::PilhaEnc() { topo = NULL; nelem = 0; } // Destrutor template <typename Tipo> PilhaEnc<Tipo>::~PilhaEnc() { Celula *aux; while (topo) { aux = topo; topo = topo->prox; delete aux; } } // Empilha template <typename Tipo> void PilhaEnc<Tipo>::empilha(const Tipo &el) throw (logic_error){ Celula *nova = new Celula; if (nova == NULL) throw logic_error("Falta memoria\n"); nova->el = el; nova->prox = topo; topo = nova; nelem++; } // Desempilha template <typename Tipo> Tipo PilhaEnc<Tipo>::desempilha() throw (logic_error) { if (nelem == 0) throw logic_error("Pilha vazia\n"); Tipo ret = topo->el; Celula *aux = topo; topo = topo->prox; delete aux; nelem--; return(ret); } // Métodos auxiliares template <typename Tipo> bool PilhaEnc<Tipo>::vazia() { return(nelem == 0); } template <typename Tipo> int PilhaEnc<Tipo>::tamanho() { return(nelem); } } #endif
  2. Bom dia, Fiz o template de pilha encadeada certo. Agora eu precisava do main.. Por exemplo: Leia um número ou um operador Se for número, empilhe Se for operador, desempilhe os últimos 2 números, realize a operação correspondente e empilhe o resultado Minha dificuldade é implementar isso no c++ Os templates abaixo no pilhaEnc.h: #ifndef _PilhaEnc_H #define _PilhaEnc_H #include <stdexcept> using std::logic_error; namespace ED { template <typename Tipo> class PilhaEnc { public: PilhaEnc(); ~PilhaEnc(); // Métodos principais void empilha(const Tipo &elem) throw (logic_error); Tipo desempilha() throw (logic_error); // Métodos auxiliares bool vazia(); int tamanho(); private: struct Celula { Tipo el; Celula *prox; }; Celula *topo; int nelem; }; // Construtor template <typename Tipo> PilhaEnc<Tipo>::PilhaEnc() { topo = NULL; nelem = 0; } // Destrutor template <typename Tipo> PilhaEnc<Tipo>::~PilhaEnc() { Celula *aux; while (topo) { aux = topo; topo = topo->prox; delete aux; } } // Empilha template <typename Tipo> void PilhaEnc<Tipo>::empilha(const Tipo &el) throw (logic_error){ Celula *nova = new Celula; if (nova == NULL) throw logic_error("Falta memoria\n"); nova->el = el; nova->prox = topo; topo = nova; nelem++; } // Desempilha template <typename Tipo> Tipo PilhaEnc<Tipo>::desempilha() throw (logic_error) { if (nelem == 0) throw logic_error("Pilha vazia\n"); Tipo ret = topo->el; Celula *aux = topo; topo = topo->prox; delete aux; nelem--; return(ret); } // Métodos auxiliares template <typename Tipo> bool PilhaEnc<Tipo>::vazia() { return(nelem == 0); } template <typename Tipo> int PilhaEnc<Tipo>::tamanho() { return(nelem); } } #endif
  3. Eu precisava de ajuda com um código para um programa para validar uma expressão aritmética com relação ao balenceamento de “()” “[]” e “{}” - Exemplo: ◦ d^{[(a+B ) * c] * [c*(a+d) ^(d+e)]} ok ◦ d^{[(a+B ) * c] * c*(a+d) ^(d+e)]} errado Usando pilha encadeada já com os templates do Pilha.h que já estão ok. #ifndef _PilhaEnc_H #define _PilhaEnc_H #include <stdexcept> using std::logic_error; namespace ED { template <typename Tipo> class PilhaEnc { public: PilhaEnc(); ~PilhaEnc(); // Métodos principais void empilha(const Tipo &elem) throw (logic_error); Tipo desempilha() throw (logic_error); // Métodos auxiliares bool vazia(); int tamanho(); private: struct Celula { Tipo el; Celula *prox; }; Celula *topo; int nelem; }; // Construtor template <typename Tipo> PilhaEnc<Tipo>::PilhaEnc() { topo = NULL; nelem = 0; } // Destrutor template <typename Tipo> PilhaEnc<Tipo>::~PilhaEnc() { Celula *aux; while (topo) { aux = topo; topo = topo->prox; delete aux; } } // Empilha template <typename Tipo> void PilhaEnc<Tipo>::empilha(const Tipo &el) throw (logic_error){ Celula *nova = new Celula; if (nova == NULL) throw logic_error("Falta memoria\n"); nova->el = el; nova->prox = topo; topo = nova; nelem++; } // Desempilha template <typename Tipo> Tipo PilhaEnc<Tipo>::desempilha() throw (logic_error) { if (nelem == 0) throw logic_error("Pilha vazia\n"); Tipo ret = topo->el; Celula *aux = topo; topo = topo->prox; delete aux; nelem--; return(ret); } // Métodos auxiliares template <typename Tipo> bool PilhaEnc<Tipo>::vazia() { return(nelem == 0); } template <typename Tipo> int PilhaEnc<Tipo>::tamanho() { return(nelem); } } #endif
×
×
  • Criar Novo...