Pārlūkot izejas kodu

refactor List desctroctor

jezv 1 gadu atpakaļ
vecāks
revīzija
b86e0339e4
1 mainītis faili ar 7 papildinājumiem un 6 dzēšanām
  1. 7 6
      List.h

+ 7 - 6
List.h

@@ -40,6 +40,7 @@ class List
     ~List()
     {
         Node<T>* currentNode = start;
+        if (currentNode == nullptr) return;
         while (currentNode->next!=nullptr)
         {
             currentNode = currentNode->next;
@@ -48,7 +49,7 @@ class List
         delete currentNode;
     }
 
-    void add(T value)
+    virtual void add(T value)
     {
         Node<T>* node = new Node<T>;
         node->value = value;
@@ -63,7 +64,7 @@ class List
         lenght++;
     }
 
-    void add(T value, int index)
+    virtual void add(T value, int index)
     {
         Node<T>* node = new Node<T>;
         node->value = value;
@@ -71,12 +72,12 @@ class List
         Node<T>* before = getNode(index-1);
         node->next = before->next;
         node->prev = before;
-        before->next->prev = node;
+        node->next->prev = node;
         before->next = node;
         lenght++;
     }
 
-    void pop()
+    virtual void pop()
     {
         // Сделать проверку на пустой список
         end = end->prev;
@@ -84,14 +85,14 @@ class List
         lenght--;
     }
 
-    void pop(Node<T>* node)
+    virtual void pop(Node<T>* node)
     {
         node->next->prev = node->prev;
         node->prev->next = node->next;
         lenght--;
     }
 
-    void pop(int index)
+    virtual void pop(int index)
     {
         if (index==0) {
             start = getNode(index+1);