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