Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. #include <iostream>
  2.  
  3.  
  4.  
  5. using namespace std;
  6.  
  7. template<typename T>
  8. class list{
  9.     class cell{
  10.         T elem;
  11.         cell *prev;
  12.         cell *next;
  13.         cell ( T e, cell *p, cell *n): elem(e),prev(p),next(n){};
  14.         friend class list<T>;
  15.        
  16.     };
  17.    
  18.     cell *first,*last;
  19. public:
  20.     using iterator=cell*;
  21.     list(){
  22.         last = new cell (T(),nullptr ,nullptr);
  23.         first = last;
  24.     }
  25.     ~list (){
  26.         clear();
  27.         delete first;
  28.     }
  29.    
  30.     iterator begin(){
  31.         return first;
  32.     }
  33.     iterator end(){
  34.         return last;
  35.     }
  36.     iterator insert (iterator donde,T que){
  37.         cell *anterior= donde->prev;
  38.         cell *aux=new cell(que,donde->prev,donde);
  39.         donde->prev= aux;
  40.         if (anterior) anterior ->next = aux;
  41.         else first = aux;
  42.         return aux;
  43.     }
  44.     iterator erase(iterator cual){
  45.        
  46.        
  47.        
  48.     }
  49.     iterator prev(iterator it){
  50.         return it->prev;
  51.     }
  52.     iterator next(iterator it){
  53.         return it->next;
  54.     }
  55.     T &retrieve(iterator it){
  56.        
  57.         return it->elem;
  58.        
  59.     }
  60.     void clear(){
  61.         while(!empty()){
  62.             erase(begin());
  63.         }
  64.     }
  65.     int size();
  66.     bool empty(){
  67.         return begin()==end();
  68.     }
  69.    
  70.    
  71.    
  72.    
  73. };
  74.  
  75.  
  76. int main(int argc, char *argv[]) {
  77.    
  78.     list <char> L;
  79.     L.insert(L.begin(), 'A');
  80.     L.insert(L.end(),'D');
  81.     list <char>::iterator it=L.begin();
  82.     it=L.next(it);
  83.     L.insert(it,'E');
  84.     for(list<char>::iterator it=L.begin();
  85.     it!=L.end(); it=L.next(it)){
  86.         cout<<L.retrieve(it);
  87.     }
  88.     cin.get();
  89.    
  90.     return 0;
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement