Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * File: InFront.h
- * Author: Diogo
- *
- * Created on 2 de Outubro de 2014, 16:56
- */
- #ifndef INFRONT_H
- #define INFRONT_H
- #include <iostream>
- #include <string>
- #include <algorithm>
- #include <deque>
- #include <vector>
- using namespace std;
- template<class T>
- class InFront {
- private:
- vector< deque<T> > seqs;
- int nrSeq;
- public:
- InFront(int nrs);
- InFront(const InFront& i);
- ~InFront();
- void insElem(const T &elem, int ns);
- void remover(int n, int ns);
- void toString(ostream &out) const;
- };
- template<class T>
- InFront<T>::InFront(int nrs) : seqs(nrs) {
- nrSeq = nrs;
- }
- template<class T>
- InFront<T>::InFront(const InFront& i) : seqs(i.seqs) {
- nrSeq = i.nrSeq;
- }
- template<class T>
- InFront<T>::~InFront() {
- }
- template<class T>
- void InFront<T>::insElem(const T& elem, int ns) {
- if (ns >= 0 && ns < nrSeq) {
- bool flag = false;
- int pos = 0;
- typename deque<T>::iterator it;
- for (it = seqs[ns].begin(); it != seqs[ns].end(); it++) {
- if (*it == elem) {
- flag = true;
- } else if (flag == false) {
- pos++;
- }
- }
- if (flag == true) {
- seqs[ns].erase(seqs[ns].begin() + pos);
- }
- seqs[ns].push_front(elem);
- cout << endl;
- } else {
- cout << "ERRO!" << endl;
- }
- }
- template<class T>
- void InFront<T>::remover(int n, int ns) {
- if (ns >= 0 && ns < nrSeq) {
- for (int i = 0; i < n; i++) {
- if (!seqs[ns].empty()) {
- seqs[ns].pop_back();
- }
- }
- } else {
- cout << "ERRO!" << endl;
- }
- }
- template<class T>
- void InFront<T>::toString(ostream& out) const {
- for (int j = 0; j < seqs.size(); j++) {
- out << "DEQUE Nº" << j+1 << ":" << endl;
- for (int i = 0; i < seqs[j].size(); i++) {
- out << "-" << seqs[j][i] << ";";
- }
- out << endl;
- }
- }
- template<class T>
- ostream &operator<<(ostream &out, const InFront<T> &i) {
- i.toString(out);
- return out;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement