For this i have to write a program that tests the correctness of the implementation.
This code is mylist.h
I am new at programming and was wondering on how to get started...
i have to write a mylist.cpp file and test its implimentation.
Code:
/* mylist.h -- a doubly-linked list */
#include <algorithm>
using namespace std;
// forward declaration of classes defined in this header
template <class T> class mylist;
template <class T> class mylink;
template <class T> class mylist_iterator;
template <class T>
class mylist
{
public:
typedef T value_type;
typedef mylist_iterator<T> iterator;
// constructors
mylist(); // default constructor
mylist(const mylist<T> & list); // copy constructor
~mylist(); // destructor
// operations
bool empty() const;
int size() const;
T & back();
T & front();
void push_front(const T & x);
void push_back(const T & x);
void pop_front();
void pop_back();
iterator begin();
iterator end();
void sort(); // sort list in O(n log n) -- EXTRA CREDIT
void insert(iterator pos, const T & x); // insert x before pos
void erase(iterator pos);
void erase(iterator first, iterator last);
protected:
mylink<T> * first_link;
mylink<T> * last_link;
unsigned int my_size;
};
template <class T>
class mylink
{
private:
mylink(const T & x);
T x;
mylink<T> * next_link;
mylink<T> * prev_link;
friend class mylist<T>;
friend class mylist_iterator<T>;
};
template <class T> class mylist_iterator
{
public:
typedef mylist_iterator<T> iterator;
// constructor
mylist_iterator(mylink<T> * current_link);
// iterator protocol
T & operator * ();
void operator = (const iterator & rhs);
bool operator == (const iterator & rhs) const;
bool operator != (const iterator & rhs) const;
iterator & operator ++ (); // preincrement, ex. ++it
iterator operator ++ (int); // postincrement, ex. it++
iterator & operator -- (); // predecrement
iterator operator -- (int); // postdecrement
protected:
mylink<T> * current_link;
friend class mylist<T>;
};