/*
 * $Id: clist.cpp 2744 2014-12-03 20:52:25Z johnoel $
 *
 * Author: David Fournier
 * Copyright (c) 2008-2012 Regents of the University of California
 */
#include "clist.h"

clist* clist::prev()
{
  clist* tmp = this->next;
  while (tmp)
  {
    if (tmp->next != this)
      tmp = tmp->next;
    else
      break;
  }
  return tmp;
}

int clist::length(const int& max)
{
  int num = 1;
  clist* tmp = this;
  while (tmp && tmp->next != this)
  {
    tmp = tmp->next;
    if (++num > max)
    {
      return -1;
    }
  }
  return num;
}

/**
Copy constructor
*/
clist::clist(const clist& t)
{
  clist& tmp=*(clist *)(&t);
  next = t.next;
  tmp.next = this;
}

/**
Destructor
*/
clist::~clist()
{
  if (next == this)
  {
    next = 0;
  }
  else
  {
    prev()->next = next;
  }
}
