Radu-Adrian Marcu / Mbed OS SOFT253_GroupA_AssignmentRepo

Dependencies:   LPS25H hts221

Fork of SOFT253_Template_Weather_OS_54 by Stage-1 Students SoCEM

Branch:
feature/listSizeLimit
Revision:
53:abb161ed4c8c
Parent:
52:b95572c3d4c4
Child:
54:53ee2d07d684
diff -r b95572c3d4c4 -r abb161ed4c8c LinkedList.cpp
--- a/LinkedList.cpp	Thu Apr 06 19:31:43 2017 +0000
+++ b/LinkedList.cpp	Thu Apr 06 19:42:34 2017 +0000
@@ -1,113 +1,114 @@
 #include "LinkedList.h"
 #include <stdio.h>
 #include <ctype.h>
-    // constructor
-    LinkedList::LinkedList(int limit)
+// constructor
+LinkedList::LinkedList(int limit)
+{
+    sizeLimit = limit;
+    currentSize = 0;
+    head = NULL; 
+}
+
+void LinkedList::addValueFront(Measure _measure){
+    Node *n = new Node();   
+    n->measure = _measure;       
+    n->next = head;         
+                            
+    head = n; 
+    
+    currentSize++;              
+}
+void LinkedList::addValueEnd(Measure _measure)
+{
+    if(head == NULL)
     {
-        size = 0;
-        head = NULL; 
+        Node *aux = new Node();
+        aux->measure = _measure;
+        aux->next = NULL;
+        head = aux;   
     }
-   
-    void LinkedList::addValueFront(Measure _measure){
-        Node *n = new Node();   
-        n->measure = _measure;       
-        n->next = head;         
-                                
-        head = n; 
+    else
+    {
+        if(currentSize >= sizeLimit)
+        {
+            popValueFRONT();                
+        }
         
-        currentSize++;              
-    }
-    void LinkedList::addValueEnd(Measure _measure)
-    {
-        if(head == NULL)
+        Node *n = head;
+        while(n->next != NULL)
         {
-            Node *aux = new Node();
-            aux->measure = _measure;
-            aux->next = NULL;
-            head = aux;   
+            n = n->next;
         }
-        else
-        {
-            if(currentSize >= sizeLimit)
-            {
-                popValueFRONT();                
-            }
-            
-            Node *n = head;
-            while(n->next != NULL)
-            {
-                n = n->next;
-            }
-            Node *aux = new Node();
-            aux->measure = _measure;
-            aux->next = NULL;
-            n->next = aux;
-        }
-        currentSize++;
+        Node *aux = new Node();
+        aux->measure = _measure;
+        aux->next = NULL;
+        n->next = aux;
     }
-    Measure LinkedList::popValueFRONT()
+    currentSize++;
+}
+Measure LinkedList::popValueFRONT()
+{
+    Node *n = head;
+    Measure _measure = n->measure;
+
+    head = head->next;
+    delete n;
+    
+    currentSize--;
+    
+    return _measure;
+}
+void LinkedList::ListAll()
+{
+    Node *n = head;
+    int i = 0;
+    while(n->next != NULL)
+    {
+        i++;
+        char *ptr = n->measure.date.ToString();
+        printf("%i. %s : T: %f | H: %f | P: %f |\r\n",i,ptr ,n->measure.temperature, n->measure.humidity, n->measure.pressure);
+        n = n->next;   
+    }   
+}
+void LinkedList::ListX(int x)
+{
+    Node *n = head;
+    int i = 0;
+    while(n->next != NULL && i < x)
+    {
+        char *ptr = n->measure.date.ToString();
+        printf("%i. %s T: %f | H: %f | P: %f |\r\n",i,ptr , n->measure.temperature, n->measure.humidity, n->measure.pressure);   
+        i++;
+        n = n->next; 
+    }   
+}
+void LinkedList::DeleteAll()
+{
+    while(head->next != NULL)
+    {
+           Node *n = head;
+           head = head -> next;
+           
+           delete n;
+           
+           currentSize = 0;
+    }   
+}
+void LinkedList::DeleteX(int x)
+{
+    int i = 0;
+    while(head->next != NULL && i < x)
     {
         Node *n = head;
-        Measure _measure = n->measure;
-
         head = head->next;
+        
         delete n;
         
-        currentSize--;
-        
-        return _measure;
-    }
-    void LinkedList::ListAll()
-    {
-        Node *n = head;
-        int i = 0;
-        while(n->next != NULL)
-        {
-            i++;
-            char *ptr = n->measure.date.ToString();
-            printf("%i. %s : T: %f | H: %f | P: %f |\r\n",i,ptr ,n->measure.temperature, n->measure.humidity, n->measure.pressure);
-            n = n->next;   
-        }   
-    }
-    void LinkedList::ListX(int x)
-    {
-        Node *n = head;
-        int i = 0;
-        while(n->next != NULL && i < x)
-        {
-            char *ptr = n->measure.date.ToString();
-            printf("%i. %s T: %f | H: %f | P: %f |\r\n",i,ptr , n->measure.temperature, n->measure.humidity, n->measure.pressure);   
-            i++;
-            n = n->next; 
-        }   
-    }
-    void LinkedList::DeleteAll()
-    {
-        while(head->next != NULL)
-        {
-               Node *n = head;
-               head = head -> next;
-               
-               delete n;
-               
-               currentSize = 0;
-        }   
-    }
-    void LinkedList::DeleteX(int x)
-    {
-        int i = 0;
-        while(head->next != NULL && i < x)
-        {
-            Node *n = head;
-            head = head->next;
-            
-            delete n;
-            
-            i++;
-        }   
-        currentSize -= x;
-    }
-    int LinkedList::GetSize()
-    {
-        return size;   
-    }
\ No newline at end of file
+        i++;
+    }   
+    currentSize -= x;
+}
+int LinkedList::GetSize()
+{
+    return currentSize;   
+}
\ No newline at end of file