소스 검색

done all circle list

jezv 1 년 전
부모
커밋
2e5c6dce00
3개의 변경된 파일19개의 추가작업 그리고 11개의 파일을 삭제
  1. 18 6
      CircleList.h
  2. BIN
      main
  3. 1 5
      main.cpp

+ 18 - 6
CircleList.h

@@ -11,7 +11,20 @@ class CircleList: public List<T>
 
         CircleList() {}
 
-        void add (T value) override{
+        ~CircleList()
+        {
+            Node<T>* currentNode = this->start;
+            for(int i = 0; i < this->lenght; i++)
+            {
+                std::cout << currentNode->value << std::endl;
+                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) {
@@ -27,13 +40,12 @@ class CircleList: public List<T>
             this->lenght++;
         }
 
-        void add (T value, int index) override{
-            static_cast<List<T>*>(this)->add(value, index);
-            return;
+        void add (T value, int index) {
+            this->List<int>::add(value, index);
         }
 
         void pop(Node<T>* n) {
-            this->pop(n);
+            this->List<int>::pop(n);
         }
 
         void pop() {
@@ -43,7 +55,7 @@ class CircleList: public List<T>
         }
 
         void pop(int index) {
-            this->pop(index);
+            this->List<int>::pop(index);
         }
 
         friend std::ostream &operator <<(std::ostream &os, CircleList &c)

BIN
main


+ 1 - 5
main.cpp

@@ -15,9 +15,5 @@ int main() {
     l.pop();
     cout << l << endl;
     l.pop(2);
-    Node<int>* n = l.get_start();
-    for(int i = 0; i < 20; i++) {
-        cout << n << endl;
-        n = n->next;
-    }
+    cout << l << endl;
 }