Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of SOFT253_Template_Weather_OS_54 by
Diff: LinkedList.cpp
- Branch:
- feature/listSizeLimit
- Revision:
- 53:abb161ed4c8c
- Parent:
- 52:b95572c3d4c4
- Child:
- 54:53ee2d07d684
--- 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
