|
@@ -2,43 +2,60 @@
|
|
#include <iostream>
|
|
#include <iostream>
|
|
|
|
|
|
template <typename T>
|
|
template <typename T>
|
|
-class CircleList: public List
|
|
|
|
|
|
+class CircleList: public List<T>
|
|
{
|
|
{
|
|
public:
|
|
public:
|
|
- Node<T>* get_start() {
|
|
|
|
- return start;
|
|
|
|
- }
|
|
|
|
|
|
+ Node<T>* get_start() {
|
|
|
|
+ return this->start;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ CircleList() {}
|
|
|
|
|
|
- void add(T value) {
|
|
|
|
- Node<T>* node = new Node<T>;
|
|
|
|
- node->value = value;
|
|
|
|
- if(start==nullptr) {
|
|
|
|
- start = node;
|
|
|
|
- end = node;
|
|
|
|
|
|
+ void add (T value) override{
|
|
|
|
+ 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) override{
|
|
|
|
+ static_cast<List<T>*>(this)->add(value, index);
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
- node->prev = end;
|
|
|
|
- node->next = start;
|
|
|
|
- end = node;
|
|
|
|
- lenght++;
|
|
|
|
- }
|
|
|
|
|
|
|
|
- void pop() {
|
|
|
|
- end->prev->next = start;
|
|
|
|
- end = end->prev;
|
|
|
|
- lenght--;
|
|
|
|
- }
|
|
|
|
|
|
+ void pop(Node<T>* n) {
|
|
|
|
+ this->pop(n);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void pop() {
|
|
|
|
+ this->end->prev->next = this->start;
|
|
|
|
+ this->end = this->end->prev;
|
|
|
|
+ this->lenght--;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ void pop(int index) {
|
|
|
|
+ this->pop(index);
|
|
|
|
+ }
|
|
|
|
|
|
- friend std::ostream &operator <<(std::ostream &os, CircleList &c)
|
|
|
|
|
|
+ friend std::ostream &operator <<(std::ostream &os, CircleList &c)
|
|
{
|
|
{
|
|
os << "( ";
|
|
os << "( ";
|
|
Node<T>* currentNode = c.start;
|
|
Node<T>* currentNode = c.start;
|
|
- while (currentNode->next!=nullptr)
|
|
|
|
|
|
+ for(int i = 0; i < c.lenght; i++)
|
|
{
|
|
{
|
|
os << currentNode->value << " = ";
|
|
os << currentNode->value << " = ";
|
|
currentNode = currentNode->next;
|
|
currentNode = currentNode->next;
|
|
}
|
|
}
|
|
- os << currentNode->value << " )";
|
|
|
|
|
|
+ os << currentNode->value << "... )";
|
|
return os;
|
|
return os;
|
|
}
|
|
}
|
|
|
|
|