From c844373c7ca513216e4930179609ea2a81b93ab4 Mon Sep 17 00:00:00 2001 From: ovidiuconstantinciobanu Date: Mon, 14 Mar 2016 04:25:14 +0200 Subject: [PATCH] Avem fisierele listCMT.h si listCMT_main.cpp adaugate. Ciobanu Ovidiu, Macovei Alexandra , Tica Teodora --- listCMT.h | 246 +++++++++++++++++++++++++++++++++++++++++++++++ listCMT_main.cpp | 51 ++++++++++ 2 files changed, 297 insertions(+) create mode 100644 listCMT.h create mode 100644 listCMT_main.cpp diff --git a/listCMT.h b/listCMT.h new file mode 100644 index 0000000..84189f8 --- /dev/null +++ b/listCMT.h @@ -0,0 +1,246 @@ +#ifndef LIST_H +#define LIST_H + +using namespace std; + +template +class List { +private: + + T* array; + int capacity; + int size; + + class Iterator{ + + private: + T* link; //"legatura" dintre iterator si un vector List + int poz; //"pozitia curenta a iteratorului" + + public: + + Iterator() //Constructor + { + poz=0; + } + + Iterator(T* array, int poz) //Constructor + { + //Se creeaza legatura intre iterator si lista, de la o pozitie specificata + + this->link=array; + this->poz=poz; + } + + T& operator *() + { + return link[poz]; + } + + T* operator ->() + { + return &link[poz]; + } + + Iterator operator ++() + { + poz++; + return Iterator(link,poz); + } + + Iterator operator ++(int) + { + Iterator aux=Iterator(link,poz); + poz++; + return aux; + } + + void operator =(const Iterator& itr) + { + link=itr.link; + poz=itr.poz; + } + + int operator !=(const Iterator& itr) + { + if(link!=itr.link) + { + return 1; + } + + if(poz!=itr.poz) + { + return 1; + } + + return 0; + } + }; + +public: + + typedef Iterator iterator; + + + List() //Constructor + { + this->capacity=1; + this->size=0; + this->array=new T[capacity]; + } + + List(int capacity) //Constructor + { + this->capacity=capacity; + this->size=0; + this->array=new T[capacity]; + } + + ~List() //Destructor + { + delete[] array; + } + + int get_size() + { + return this->size; + } + + int get_capacity() + { + return this->capacity; + + } + + T get_element(int index) + { + return this->array[index]; + } + + void insert(const T& element, unsigned index) + { + if(size+1index;i--) + { + array[i]=array[i-1]; + } + array[index]=element; + size++; + } + } + } + + void remove(unsigned index) + { + if(index>=size || size==0) //Daca indexul nu este valid sau daca vectorul este gol + { + cout<<"Operatie invalida"<=0;i--) + { + array[i]=array[i-1]; + } + } + + array[0]=element; + size++; + } + + iterator begin() + { + return Iterator(this->array,0); + } + + iterator end() + { + return Iterator(this->array,this->size-1); + } + +}; + +#endif diff --git a/listCMT_main.cpp b/listCMT_main.cpp new file mode 100644 index 0000000..e33c7fc --- /dev/null +++ b/listCMT_main.cpp @@ -0,0 +1,51 @@ + /*Ciobanu Ovidiu~~~~~~~~Macovei Alexandra~~~~~~~~Tica Teodora */ + /* 312 CA */ +#include +#include"listCMT.h" +struct chestie /*colega mea a ramas fara inspiratie */ +{ + int a, b; +}; +int main() { + List lst; + // Initializarea cu o dimensiune n. + int n; + cout << "n = "; + cin >> n; + cout<<"Elementele: \n"; + for ( int i = 0; i < n; ++i ) { + int x; + cin >> x; + // lst.push_front(x); + lst.push_back(x); + } + // cout<<"Push front: "; + cout<<"Push back: "; + int sz = lst.get_size() - 1; + for ( int i =0; i <= sz; ++i ) { + cout<< lst.get_element(i) << "-" << i << " "; + } + cout<< "\n"; + List::iterator itr1; + List::iterator itr2; + itr1 = lst.begin(); + itr2 = lst.end(); + cout<< "Begin: " << *itr1; + cout<< "\nEnd: " << *itr2; + + lst.remove(2); + cout<< "\n"; + + while( itr1 != itr2 ) + { + cout<< *itr1 << " "; + itr1++; + } + cout<< endl; + List y; + List::iterator itrC; + y.push_back({19,96}); + itrC=y.end(); + cout<a; + +}