1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- #include "List/List.h"
- #include <iostream>
- template <typename T>
- class CircleList: public List<T>
- {
- public:
- Node<T>* get_start() {
- return this->start;
- }
- CircleList() {}
- ~CircleList()
- {
- Node<T>* currentNode = this->start;
- for(int i = 0; i < this->lenght; i++)
- {
- currentNode = currentNode->next;
- delete currentNode->prev;
- }
- this->start = nullptr;
- this->end = nullptr;
- }
- void add (T value) {
- Node<T>* node = new Node<T>;
- node->value = value;
- if(this->start==nullptr) {
- this->start = node;
- this->end = node;
- return;
- }
- node->prev = this->end;
- node->next = this->start;
- this->end->next = node;
- this->start->prev = node;
- this->end = node;
- this->lenght++;
- }
- void add (T value, int index) {
- this->List<int>::add(value, index);
- }
- void pop(Node<T>* n) {
- if (n == this->start) this->start = this->start->next;
- this->List<int>::pop(n);
- }
- void pop() {
- this->end->prev->next = this->start;
- this->end = this->end->prev;
- this->lenght--;
- }
- void pop(int index) {
- this->List<int>::pop(index);
- }
- friend std::ostream &operator <<(std::ostream &os, CircleList &c)
- {
- os << "( ";
- Node<T>* currentNode = c.start;
- for(int i = 0; i < c.lenght; i++)
- {
- os << currentNode->value << " = ";
- currentNode = currentNode->next;
- }
- os << currentNode->value << "... )";
- return os;
- }
- };
|