75 lines
1.1 KiB
C++
75 lines
1.1 KiB
C++
#ifndef _LIST_H_
|
|
#define _LIST_H_
|
|
|
|
#include <iostream>
|
|
#include <string>
|
|
|
|
// TDDE18 - Lab 6 - Templates
|
|
// Header file
|
|
|
|
|
|
template <typename T>
|
|
class List
|
|
{
|
|
public:
|
|
List();
|
|
~List() { delete first; }
|
|
|
|
void insert(T const& d);
|
|
|
|
List(List const&);
|
|
List(List&&);
|
|
List& operator=(List const&);
|
|
List& operator=(List&&);
|
|
|
|
private:
|
|
|
|
class Link
|
|
{
|
|
public:
|
|
Link(T const& d, Link* n)
|
|
: data(d), next(n) {}
|
|
~Link() { delete next; }
|
|
|
|
friend class List;
|
|
|
|
static Link* clone(Link const*);
|
|
|
|
private:
|
|
|
|
T data;
|
|
Link* next;
|
|
};
|
|
|
|
Link* first;
|
|
|
|
public:
|
|
|
|
using value_type = T;
|
|
|
|
class Iterator
|
|
{
|
|
friend List;
|
|
public:
|
|
Iterator& operator++();
|
|
T& operator*() const;
|
|
|
|
bool operator!=(Iterator const& other) const;
|
|
bool operator==(Iterator const& other) const;
|
|
|
|
private:
|
|
// Private constructor
|
|
Iterator(Link* ln);
|
|
|
|
Link* l;
|
|
};
|
|
|
|
Iterator begin() const;
|
|
Iterator end() const;
|
|
};
|
|
|
|
template <typename T>
|
|
std::ostream& operator<<(std::ostream& os, const List<T>& lst);
|
|
|
|
#include "list.tcc"
|
|
#endif
|