#include #include "lab4llist.h" /***************************************************************** * LinkedList *****************************************************************/ // Default constructor LinkedList::LinkedList() { // TODO: write this. Since a new list shouldn't contain anything, // you don't actually need to allocate any memory here, just set // initial values for your private members. } // Destructor LinkedList::~LinkedList() { // Free up all of the memory that was allocated in this list while (head) { Node* temp = head; head = head->next; delete temp; } } // Insert value "val" into position "pos" void LinkedList::insert(val_t val, unsigned int pos) { // TODO: write this. It should be similar to the insert function // from lab 1. If you like, you may define a private helper function // that can be called recursively to perform the removal, since // list operations are slightly easier when done recurisvely. } // Remove a value at position "pos" void LinkedList::remove(unsigned int pos) { // TODO: write this } // Get a value from the list val_t LinkedList::retrieve(unsigned int pos) { // TODO: For extra credit, add appropriate exceptions here // to prevent retrieving from a "pos" larger than the size of // the list. // Start at the beginning of the list Node* cur = head; // Advance "pos" values for (unsigned int i = 0; i < pos; ++i) { cur = cur->next; } // Return the value return cur->val; } // Quickly check if there is data bool LinkedList::isEmpty() { return (head == NULL); } // Check how much data we have unsigned int LinkedList::size() { // TODO: write this return 0; } // Return an iterator to the beginning of our list LinkedListIterator LinkedList::begin() { LinkedListIterator ret; // TODO: finish this, set the internals of "ret" to have it point to // the beginning of the current LinkedList. return ret; } // Return an iterator to the end of our list LinkedListIterator LinkedList::end() { LinkedListIterator ret; // TODO: finish this, set the internals of "ret" to have it point to // the end of the current LinkedList. (HINT: if ret has a Node* in // it, it should be pointing to NULL, not the last Node*!) return ret; } // If you implement your iterator and LinkedList correctly, // the LinkedList version of this function should be // identical except for the type names. ostream& operator << (ostream& outStream, LinkedList& toPrint) { // Do the special case of an empty list. if (toPrint.isEmpty()) { outStream << "[]"; return outStream; } // Get an iterator LinkedListIterator i = toPrint.begin(); // Print out [ and the first element outStream << "[" << *i; // Update the iterator ++i; // Loop through the rest of the data for (; i != toPrint.end(); ++i) { outStream << ", " << *i; } // Print out the closing ] outStream << "]"; // Return return outStream; } /***************************************************************** * LinkedListIterator *****************************************************************/ // Default constructor LinkedListIterator::LinkedListIterator() { // TODO: write this } // Copy constructor LinkedListIterator::LinkedListIterator(const LinkedListIterator& other) { // TODO: write this } // Equality operator bool const LinkedListIterator::operator ==(LinkedListIterator& other) { // TODO: write this return false; } // Inequality operator bool LinkedListIterator::operator !=(const LinkedListIterator& other) { // TODO: write this return false; } // Dereference operator, returns the value in the list currently // "pointed at" by our iterator. val_t LinkedListIterator::operator*() { // TODO: write this return val_t(); } // Advance to the next value LinkedListIterator& LinkedListIterator::operator++() { // TODO: write this return *this; } // Go back to the previous value LinkedListIterator& LinkedListIterator::operator--() { return *this; }