1 | /* emacs edit mode for this file is -*- C++ -*- */ |
---|
2 | /* $Id: ftmpl_list.h,v 1.8 2005-01-13 15:10:23 Singular Exp $ */ |
---|
3 | |
---|
4 | #ifndef INCL_LIST_H |
---|
5 | #define INCL_LIST_H |
---|
6 | |
---|
7 | #include <factoryconf.h> |
---|
8 | |
---|
9 | #ifndef NOSTREAMIO |
---|
10 | #include <iostream.h> |
---|
11 | #endif /* NOSTREAMIO */ |
---|
12 | |
---|
13 | template <class T> |
---|
14 | class ListIterator; |
---|
15 | |
---|
16 | template <class T> |
---|
17 | class List; |
---|
18 | |
---|
19 | #ifndef NOSTREAMIO |
---|
20 | template <class T> |
---|
21 | std::ostream& operator<< ( std::ostream &, const List<T> &); |
---|
22 | #endif |
---|
23 | |
---|
24 | template <class T> |
---|
25 | class ListItem |
---|
26 | { |
---|
27 | private: |
---|
28 | ListItem * next; |
---|
29 | ListItem * prev; |
---|
30 | T * item; |
---|
31 | public: |
---|
32 | ListItem( const ListItem<T>& ); |
---|
33 | ListItem( const T&, ListItem<T>*, ListItem<T>* ); |
---|
34 | ListItem( T* , ListItem<T>* , ListItem<T>* ); |
---|
35 | ~ListItem(); |
---|
36 | ListItem<T>& operator= ( const ListItem<T>& ); |
---|
37 | ListItem<T>* getNext(); |
---|
38 | ListItem<T>* getPrev(); |
---|
39 | T& getItem(); |
---|
40 | #ifndef NOSTREAMIO |
---|
41 | void print ( ostream& ); |
---|
42 | #endif /* NOSTREAMIO */ |
---|
43 | friend class ListIterator<T>; |
---|
44 | friend class List<T>; |
---|
45 | }; |
---|
46 | |
---|
47 | template <class T> |
---|
48 | class List |
---|
49 | { |
---|
50 | private: |
---|
51 | ListItem<T> *first; |
---|
52 | ListItem<T> *last; |
---|
53 | int _length; |
---|
54 | public: |
---|
55 | List(); |
---|
56 | List( const List<T>& ); |
---|
57 | List( const T& ); |
---|
58 | ~List(); |
---|
59 | List<T>& operator= ( const List<T>& ); |
---|
60 | void insert ( const T& ); |
---|
61 | void insert ( const T&, int (*cmpf)( const T&, const T& ) ); |
---|
62 | void insert ( const T&, int (*cmpf)( const T&, const T& ), void (*insf)( T&, const T& ) ); |
---|
63 | void append ( const T& ); |
---|
64 | int isEmpty() const; |
---|
65 | int length() const; |
---|
66 | T getFirst() const; |
---|
67 | void removeFirst(); |
---|
68 | T getLast() const; |
---|
69 | void removeLast(); |
---|
70 | void sort ( int (*) ( const T&, const T& ) ); |
---|
71 | #ifndef NOSTREAMIO |
---|
72 | void print ( ostream & ) const; |
---|
73 | friend ostream& operator<< <T>( ostream & os, const List<T> & l ); |
---|
74 | #endif /* NOSTREAMIO */ |
---|
75 | friend class ListIterator<T>; |
---|
76 | }; |
---|
77 | |
---|
78 | #ifndef NOSTREAMIO |
---|
79 | template <class T> |
---|
80 | ostream& operator<< ( ostream & os, const List<T> & l ); |
---|
81 | #endif /* NOSTREAMIO */ |
---|
82 | |
---|
83 | template <class T> |
---|
84 | class ListIterator { |
---|
85 | private: |
---|
86 | List<T> *theList; |
---|
87 | ListItem<T> *current; |
---|
88 | public: |
---|
89 | ListIterator(); |
---|
90 | ListIterator( const ListIterator<T>& ); |
---|
91 | ListIterator( const List<T>& ); |
---|
92 | ~ListIterator(); |
---|
93 | ListIterator<T>& operator = ( const ListIterator<T>& ); |
---|
94 | ListIterator<T>& operator = ( const List<T>& ); |
---|
95 | T& getItem() const; |
---|
96 | int hasItem(); |
---|
97 | void operator++(); |
---|
98 | void operator--(); |
---|
99 | void operator++( int ); |
---|
100 | void operator--( int ); |
---|
101 | void firstItem(); |
---|
102 | void lastItem(); |
---|
103 | void insert( const T& ); |
---|
104 | void append( const T& ); |
---|
105 | void remove( int moveright ); |
---|
106 | }; |
---|
107 | |
---|
108 | template <class T> |
---|
109 | List<T> Union ( const List<T>&, const List<T>& ); |
---|
110 | |
---|
111 | template <class T> |
---|
112 | List<T> Difference ( const List<T>&, const List<T>& ); |
---|
113 | |
---|
114 | template <class T> |
---|
115 | List<T> Union ( const List<T>&, const List<T>&, int (*cmpf)( const T&, const T& ), void (*insf)( T&, const T& ) ); |
---|
116 | |
---|
117 | template <class T> |
---|
118 | T prod ( const List<T>& ); |
---|
119 | |
---|
120 | #endif /* ! INCL_LIST_H */ |
---|