#include #include "lab3llist.h" /***************************************************************** * LinkedList *****************************************************************/ // Default constructor LinkedList::LinkedList() { // TODO: write this. It needs to initialize the private values // of the LinkedList type } // Destructor LinkedList::~LinkedList() { // TODO: write this. It needs to delete the Nodes that were allocated // for the linked list } // Insert value "val" into position "pos" void LinkedList::insert(val_t val, unsigned int pos) { // TODO: write this. It needs to allocate a new Node using // new and insert it into the correct position. You can look // at the Lab 1 solutions or your own Lab 1 code for information. } // Remove a value at position "pos" void LinkedList::remove(unsigned int pos) { // TODO: write this. It should remove the Node occuring at the // given position, and call delete on it to prevent memory leaks. } // Get a value from the list val_t LinkedList::retrieve(unsigned int pos) { // TODO: write this. It should return the value of // the Node at the given position. // This line is wrong, but is in place so the code can compile until // you write the rest of this function return val_t(); } // Quickly check if there is data bool LinkedList::isEmpty() { // TODO: write this. It should be 1 line of code return true; } // Check how much data we have unsigned int LinkedList::size() { // TODO: write this, it should return the number of Nodes in the linked // list. // This line is wrong, and is just a placeholder so the code compiles. return 0; } // Return an iterator to the beginning of our list LinkedListIterator LinkedList::begin() { // TODO: write this. It should return a new LinkedListIterator // that points to the beginning of this LinkedList. (That // doesn't mean use "new" on it, it just means return a new statically // declared one.) // This line is just a placeholder so that the code compiles. return LinkedListIterator(); } // Return an iterator to the end of our list LinkedListIterator LinkedList::end() { // TODO: write this. It should return a new LinkedListIterator // that points to the end of this LinkedList. Same comments // about scope from begin() apply. // This is, guess what? Just a placeholder! return LinkedListIterator(); } // 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. It should initialize all of the // private members of a LinkedListIterator to some default // value. } // Copy constructor LinkedListIterator::LinkedListIterator(const LinkedListIterator& other) { // TODO: write this, it should initialize all of the // private members of a LinkedListIterator to be the same as // the private members of another LinkedListIterator } // Equality operator bool const LinkedListIterator::operator ==(LinkedListIterator& other) { // TODO: write this. Think of which members of the iterator need // to be the same for the iterators to be considered equivalent // This is just a placeholder return false; } // Inequality operator bool LinkedListIterator::operator !=(const LinkedListIterator& other) { // TODO: write this. It ought to be the exact opposite of the // == operator. In fact, you can probably just do !(*this == other) // if you are daring. return false; } // Dereference operator, returns the value in the list currently // "pointed at" by our iterator. val_t LinkedListIterator::operator*() { // TODO: write this. It should return the value currently pointed // to. return val_t(); } // Advance to the next value LinkedListIterator& LinkedListIterator::operator++() { // TODO: write this. It should make the iterator point to the next // element. // This return value is probably correct. return *this; } // Go back to the previous value LinkedListIterator& LinkedListIterator::operator--() { // TODO: write this. It should make the iterator point to the // previous element. This is going to be a slow operation. // This return value is probably correct. return *this; }