CircleList.h 925 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "List/List.h"
  2. #include <iostream>
  3. template <typename T>
  4. class CircleList: public List
  5. {
  6. public:
  7. Node<T>* get_start() {
  8. return start;
  9. }
  10. void add(T value) {
  11. Node<T>* node = new Node<T>;
  12. node->value = value;
  13. if(start==nullptr) {
  14. start = node;
  15. end = node;
  16. return;
  17. }
  18. node->prev = end;
  19. node->next = start;
  20. end = node;
  21. lenght++;
  22. }
  23. void pop() {
  24. end->prev->next = start;
  25. end = end->prev;
  26. lenght--;
  27. }
  28. friend std::ostream &operator <<(std::ostream &os, CircleList &c)
  29. {
  30. os << "( ";
  31. Node<T>* currentNode = c.start;
  32. while (currentNode->next!=nullptr)
  33. {
  34. os << currentNode->value << " = ";
  35. currentNode = currentNode->next;
  36. }
  37. os << currentNode->value << " )";
  38. return os;
  39. }
  40. };