#include "node.h" #include "linkedlist.h" #include #include LinkedList::LinkedList(){ head = NULL; } void LinkedList::addFirst(int value){ head = new Node(value, head); } int LinkedList::removeFirst(){ assert(head != NULL); int returnMe = head->value(); head = head->next(); return returnMe; } int LinkedList::getFirst() const{ return head->value(); } bool LinkedList::contains(int value) const{ Node* finger = head; while( finger != NULL && finger->value() != value ){ finger = finger->next(); } return finger != NULL; } void LinkedList::set(int index, int value){ Node* finger = head; for( int i = 0; i < index && head != NULL; i++ ){ finger = finger->next(); } if( finger != NULL ){ finger->setValue(value); } } void LinkedList::clear(){ head = NULL; } bool LinkedList::isEmpty(){ return head == NULL; }