Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- template<typename T>
- class list{
- class cell{
- T elem;
- cell *prev;
- cell *next;
- cell ( T e, cell *p, cell *n): elem(e),prev(p),next(n){};
- friend class list<T>;
- };
- cell *first,*last;
- public:
- using iterator=cell*;
- list(){
- last = new cell (T(),nullptr ,nullptr);
- first = last;
- }
- ~list (){
- clear();
- delete first;
- }
- iterator begin(){
- return first;
- }
- iterator end(){
- return last;
- }
- iterator insert (iterator donde,T que){
- cell *anterior= donde->prev;
- cell *aux=new cell(que,donde->prev,donde);
- donde->prev= aux;
- if (anterior) anterior ->next = aux;
- else first = aux;
- return aux;
- }
- iterator erase(iterator cual){
- }
- iterator prev(iterator it){
- return it->prev;
- }
- iterator next(iterator it){
- return it->next;
- }
- T &retrieve(iterator it){
- return it->elem;
- }
- void clear(){
- while(!empty()){
- erase(begin());
- }
- }
- int size();
- bool empty(){
- return begin()==end();
- }
- };
- int main(int argc, char *argv[]) {
- list <char> L;
- L.insert(L.begin(), 'A');
- L.insert(L.end(),'D');
- list <char>::iterator it=L.begin();
- it=L.next(it);
- L.insert(it,'E');
- for(list<char>::iterator it=L.begin();
- it!=L.end(); it=L.next(it)){
- cout<<L.retrieve(it);
- }
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement