Facebook
From Crippled Terrapin, 7 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 215
  1.  
  2.  
  3.  
  4. #pragma once
  5. #include<string>
  6.  
  7.  
  8. template <class T>
  9. class List
  10. {
  11. public:
  12.        
  13.  
  14.         class Element
  15.         {
  16.         public:
  17.                 T t_value;
  18.                 Element * next;
  19.                 Element * previous;
  20.  
  21.                 Element(T value);
  22.                 void detach();
  23.                 void attachBefore(Element *next);
  24.         };
  25.         List();
  26.         void insert(int index);
  27.         Element &  getElement(int index);
  28. private:
  29.         Element * guard;
  30.         int rozmiar;
  31. };
  32.  
  33.  
  34. template<class T>
  35. inline List<T>::Element::Element(T value)
  36. {
  37.         t_value = value;
  38. }
  39. template<class T>
  40. inline void List<T>::Element::detach()
  41. {
  42.  
  43.         this->next->previous = this->previous;
  44.         this->previous->next = this->next;
  45.  
  46. }
  47.  
  48. template<class T>
  49. inline void List<T>::Element::attachBefore(Element * next)
  50. {
  51.         Element *prev;
  52.         prev = next->previous;
  53.         this->next = next;
  54.         this->previous = prev;
  55.         next->previous = this;
  56.         prev->next = this;
  57. }
  58.  
  59. template<class T>
  60. inline List<T>::List()
  61. {
  62.         this->rozmiar = 0;
  63.         this->guard = new Element(null);
  64.         this->guard->next = this->guard;
  65.         this->guard->previous = this->guard;
  66. }
  67.  
  68. template<class T>
  69. inline void List<T>::insert(int index)
  70. {
  71. }
  72.  
  73. template<class T>
  74. inline Element  List<T>::getElement(int index)
  75. {
  76.         Element * element;
  77.         element = this->guard->next;
  78.         return element;
  79. }
  80.  
  81.  
  82.  
  83.