Statistics
| Revision:

root / trunk / src / tools99 / clist.cpp @ 1106

History | View | Annotate | Download (769 Bytes)

1
/*
2
 * $Id: clist.cpp 1106 2013-07-11 20:54:23Z johnoel $
3
 *
4
 * Author: David Fournier
5
 * Copyright (c) 2008-2012 Regents of the University of California
6
 */
7
#include "clist.h"
8

    
9
#ifdef HERE
10
  #undef HERE
11
#endif
12
#define HERE cout << "reached line " << __LINE__ << " in " << __FILE__ << endl;
13
clist * clist::prev(void)
14
{
15
  clist * tmp = this->next;
16
  while (tmp->next != this) tmp = tmp->next;
17
  return (tmp);
18
}
19

    
20
int  clist::length(const int & max)
21
{
22
  int num = 1;
23
  clist * tmp = this;
24
  while (tmp->next != this)
25
  {
26
    tmp = tmp->next;
27
    if (++num > max)
28
    {
29
      return (-1);
30
    }
31
  }
32
  return (num);
33
}
34

    
35
clist::clist(const clist & t)
36
{
37
  clist& tmp=*(clist *)(&t);
38
  next = t.next;
39
  tmp.next = this;
40
}
41

    
42
clist::~clist()
43
{
44
  if (next == this)
45
  {
46
    next = 0;
47
  }
48
  else
49
  {
50
    prev()->next = next;
51
  }
52
}