Advertisement
Sanlover

List.h

Oct 26th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #ifndef DYNAMICSTRUCTURES_LIST_H
  2. #define DYNAMICSTRUCTURES_LIST_H
  3. #include <iostream>
  4.  
  5. #define THROW_OUT_OF_RANGE_EXCEPTION throw std::exception("Attempt to access an element out of range")
  6.  
  7. template <typename T>
  8. class List
  9. {
  10. private:
  11. struct Node
  12. {
  13. T value;
  14. Node* next;
  15. Node* prev;
  16.  
  17. Node(const T& value, Node* next, Node* prev) : value(value), next(next), prev(prev) {};
  18. };
  19.  
  20. Node* first_;
  21. Node* last_;
  22. size_t size_;
  23. public:
  24.  
  25. List();
  26. explicit List(const size_t count);
  27. explicit List(const size_t count, const T& value);
  28.  
  29. void resize(const size_t count);
  30. void resize(const size_t count, const T& value);
  31.  
  32. void pushFront(const T& value);
  33. void popFront();
  34.  
  35. void pushBack(const T& value);
  36. void popBack();
  37.  
  38. void insertAfter(const size_t id, const T& value);
  39. void eraseAfter(const size_t id);
  40.  
  41. void clear();
  42.  
  43. _NODISCARD size_t size() const;
  44. _NODISCARD bool empty() const;
  45.  
  46. T& operator[](const size_t id);
  47. };
  48.  
  49. #include "List.tpp"
  50. #endif //DYNAMICSTRUCTURES_LIST_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement