Radu-Adrian Marcu / Mbed OS SOFT253_GroupA_AssignmentRepo

Dependencies:   LPS25H hts221

Fork of SOFT253_Template_Weather_OS_54 by Stage-1 Students SoCEM

LinkedList.cpp

Committer:
FairyMental
Date:
2017-04-06
Revision:
44:b523c9a9dd97
Parent:
43:3983059e0d91
Child:
45:9a33f2bc2b4e

File content as of revision 44:b523c9a9dd97:

#include "LinkedList.h"
#include <stdio.h>
#include <ctype.h>
    // constructor
    LinkedList::LinkedList()
    {
        size = 0;
        head = NULL; 
    }
   
    void LinkedList::addValueFront(Measure _measure){
        Node *n = new Node();   
        n->measure = _measure;       
        n->next = head;         
                                
        head = n; 
        
        size++;              
    }
    void LinkedList::addValueEnd(Measure _measure)
    {
        if(head == NULL)
        {
            Node *aux = new Node();
            aux->measure = _measure;
            aux->next = NULL;
            head = aux;   
        }
        else
        {
            Node *n = head;
            while(n->next != NULL)
            {
                n = n->next;
            }
            Node *aux = new Node();
            aux->measure = _measure;
            aux->next = NULL;
            n->next = aux;
        }
        size++;
    }
    Measure LinkedList::popValueFRONT()
    {
        Node *n = head;
        Measure _measure = n->measure;

        head = head->next;
        delete n;
        
        size--;
        
        return _measure;
    }
    void LinkedList::ListAll()
    {
        Node *n = head;
        int i = 0;
        while(n->next != NULL)
        {
            i++;
            printf("%i. T: %f | H: %f | P: %f |\r\n",i ,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)
        {
            printf("%i. T: %f | H: %f | P: %f |\r\n",i , 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;
               
               size = 0;
        }   
    }
    void LinkedList::DeleteX(int x)
    {
        int i = 0;
        while(head->next != NULL && i < x)
        {
            Node *n = head;
            head = head->next;
            
            delete n;
            
            i++;
        }   
        size -= x;
    }