Skip to content
Snippets Groups Projects
Commit abc14b76 authored by Ítalo Epifânio de Lima e Silva's avatar Ítalo Epifânio de Lima e Silva
Browse files

Inicia questao 2 da lista

parent c931054a
No related branches found
No related tags found
No related merge requests found
File added
File added
#ifndef _CONJUNTO_DE_PILHAS_HPP_
#define _CONJUNTO_DE_PILHAS_HPP_
#include "../../../listaLigada/listaDuplamenteLigada.hpp"
#include <vector>
template <typename T>
class ConjuntoDePilhas{
private:
int tamanhoMaxPilha;
public:
std::vector<ListaDuplamenteLigada<T>> conjuntoDePilhas;
ConjuntoDePilhas(int tamanhoMaxPilha){
this->tamanhoMaxPilha = tamanhoMaxPilha;
ListaDuplamenteLigada<T> nova;
conjuntoDePilhas.push_back(nova);
}
bool full(ListaDuplamenteLigada<T> &l){
return l.tamanho >= this->tamanhoMaxPilha;
}
void printConjunto(){
conjuntoDePilhas[0].print();
for(int i = 0; i < (int)conjuntoDePilhas.size(); i++){
conjuntoDePilhas[i].print();
}
}
void push(T valor){
// Percorre o conjunto de pilhas
for(int i = 0; i < (int)conjuntoDePilhas.size(); i++){
// Se o index estiver não tiver cheio eu dou
// push na pilha
// Se estiver cheio crio uma nova pilha
if(! full(conjuntoDePilhas[i])){
std::cout << "pushou" << '\n';
conjuntoDePilhas[i].push_front(valor);
}else{
std::cout << "criou nova pilha" << '\n';
ListaDuplamenteLigada<T> nova;
conjuntoDePilhas.push_back(nova);
}
}
}
};
#endif
PROG = bin/exec
CC = g++
CPPFLAGS = -O0 -g -W -Wall -pedantic -std=c++11
OBJS = main.o
$(PROG) : $(OBJS)
$(CC) $(OBJS) -o $(PROG)
mv *.o build/
main.o : include/conjuntoDePilhas.hpp
$(CC) $(CPPFLAGS) -c src/main.cpp
clean:
rm -f build/*.o
#include "../include/conjuntoDePilhas.hpp"
int main() {
ConjuntoDePilhas <int> l(2);
l.push(1);
l.push(2);
l.push(3);
l.printConjunto();
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment