///////////////////
// exercises.hh: //
///////////////////

#ifndef EXERCISES_HH
#define EXERCISES_HH

#include <list>

template<typename T>
class Stack
{
public:
  bool isEmpty() const;
  void push(T const &e);
  T const &pop();
private:
  std::list<T> _stack;
};

#include "exercises.tcc"

#endif // EXERCISES_HH

////////////////////
// exercises.tcc: //
////////////////////

// Exercise 1
template<typename T>
T abs(T const &x)
{
  if(x < 0)
    return -x;
  return x;
}

// Exercise 2
template<typename T>
bool Stack<T>::isEmpty() const
{
  return _stack.empty();
}

template<typename T>
void Stack<T>::push(T const &e)
{
  _stack.push_front(e);
}

template<typename T>
T const &Stack<T>::pop()
{
  T const &first = _stack.front();
  _stack.pop_front();
  return first;
}

// Exercise 3
template<int SIZE, typename T>
T *makeArray(T const &e)
{
  T *array = new T[SIZE];
  for(int i = 0; i < SIZE; ++i)
    array[i] = e;

  return array;
}