#include "LinkedList.h"

LinkedList::~LinkedList() {
  LinkNode* current = head;
  LinkNode* nextLinkNode;
  while (current != NULL) {
    nextLinkNode = current->next;
    delete current;
    current = nextLinkNode;
  }
}

/**
 * Returns the count of the number of elements in the Collection
 */
int LinkedList::size() const {
  LinkNode* current = head;
  int count = 0;
  while (current != NULL) {
    count++;
    current = current->next;
  }
  return count;
}

/**
 * Adds the given integer value to the Collection. Placement index of
 * the newly added element is assumed to be first (index=0).
 */
void LinkedList::add(int pValue) {
  LinkNode* newNode = new LinkNode(pValue);
  
  newNode->next = head;
  head = newNode;
}

/**
 * Returns the integer value of the first element of the Collection.
 */
int LinkedList::first() const {
  return head->data;
}
