IteratedList.h
#pragma once
//DO NOT INCLUDE LISTITERATOR//DO NOT CHANGE THIS PART
class ListIterator;
#define NULL_TELEM -11111;
typedefint TElem;class IteratedList {
private:
//TODO - Representation
//DO NOT CHANGE THIS PART
friendclass ListIterator;
public: // constructor
IteratedList (); // returns the number of elements from the list
int size() const; // verifies if the list is empty
bool isEmpty() const; // returns the first position from the list
ListIterator first() const; // returns the element from the given position
//throws an exception if the position is not valid
TElem getElement(ListIterator pos) const; // changes the element from the current position to the given one.
//returns the old value from the position
//throws exception if the position is not valid
TElem setElement(ListIterator pos, TElem e); // adds a new element to the end of the list
void addToEnd(TElem e);
//adds a new element to the beginning of the list
void addToBeginning(TElem e); // // adds a new element after the current element from the iterator
//after addition, pos points to the newly added element
//throws an exception if pos is not valid
void addToPosition(ListIterator& pos, TElem e); // removes the element from position pos
//returns the removed element
//after removal pos is positioned on the next element (the one after the removed one) or it is invalid if the last element was removed
//throws an exception if pos is not valid
TElem remove(ListIterator& pos); // searches for the first occurrance of an element
//returns an iterator that points to the element, if it appear in the list, or an invalid iterator if the element is not in the list
ListIterator search(TElem e) const; //destructor ~IteratedList();
};
break it down.
the first thing you probably want to do with any new class is write its constructor(s) so you can create an object of that type and give it a quick 'duh' test that it compiles and works.
then fill in the most basic stuff first: a list is no good if you can't add an item to it, and adding an item to is is no good if you can't get to that and print it back out...
so try starting with those 3 things, a constructor, an add of some sort (top or bottom, doesn't matter which one you do first, top is easiest and most efficient if its a linked list base) and a getter of some flavor that can retrieve what you put in.
then maybe work on getting its current size, ... just pick something, add it, test it, repeat one by one. If you pay attention, some of the methods can use each other, eg is empty and size are redundant: if size is 0, its empty... right? so is empty is literally one line: return !size() since 0 size is empty and not zero is true...
assuming this is a homework classic linked list, make sure you understand the pointer requirement.
a typical linked list is
struct llist
{
llist*next; // this pointer to its own type is what makes it work.
///other stuff
};
this is a hefty assignment. That means you should have a fair bit of background to do all the things it asks for. If you have been able to do your work up to now, give it a shot and ask specific questions if you get stuck. If you have not been able to do your work up to this point, this may be the one that finally highlights that you need to back up and learn the previous material.
The code you posted looks like it's been word-wrapped. Is your copy correct? I'd hate to try to implement this based on what's posted here. For example:
1 2 3
public: // constructor
IteratedList (); // returns the number of elements from the list
int size() const; // verifies if the list is empty
probably should be
1 2 3 4 5 6
public:
// constructor
IteratedList ();
// returns the number of elements from the list
int size() const;
In IteratedList.cpp, you have a TODO implementation for IteratedList's destructor, but no destructor has been declared. You may need to ask the prof about this since the the destructor would fall into the public section labelled "DO NOT CHANGE"