summaryrefslogtreecommitdiff
path: root/flower/list.cc
blob: 741e4ee97c87b48830c3d703ae66c69ad80b1d0a (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#ifndef LIST_CC
#define LIST_CC

#include "list.hh"

template<class T>
List<T>::List(List const&src)
{
    set_empty();
    // probably el stupido
    for (Cursor<T> c(src); c.ok(); c++)
	bottom().add(c);
}

template<class T>
void
List<T>::OK() const
{
    int i = size_;
    Link<T> *lp = top_;
    while (i--) {
	assert(lp);
	lp->OK();
	lp = lp->next();
    }
    assert(!lp);
     i = size_;
    lp = bottom_;
    while (i--) {
	assert(lp);
	lp->OK();
	lp = lp->previous();
    }
    assert(!lp);
}

template<class T>
Cursor<T>
List<T>::top()
{
#if 0 
    // ?? waarvoor is deze if ? 
    if ( top_ )			// equivalent: if ( size_ )
	{
	Link<T>* t = top_->previous();
	assert( t != top_ );	// silly link
	while ( t )
	    {
		assert(false);	// this is even more silly.
	    top_ = t;
	    t = top_->previous();
	    }
	}
#endif
    
// list empty: Cursor not ok()
    return Cursor<T>( *this, top_ );
}


template<class T>
Cursor<T>
List<T>::bottom()
{
    /* wat is dit voor zooi? kan dit niet weg?

    (invarianten!)
    */
    if ( bottom_ )		// equivalent: if ( size_ )
	{
	Link<T>* b = bottom_->next();
	assert( b != bottom_ );	// silly link    
	while ( b )
	    {
	    bottom_ = b;
	    b = bottom_->next();
	    }
	}
    				// list empty: Cursor not ok()
    return Cursor<T>( *this, bottom_ );
}


#endif