1 | // emacs edit mode for this file is -*- C++ -*- |
---|
2 | // $Id: ftmpl_list.h,v 1.2 1997-04-15 10:11:37 schmidt Exp $ |
---|
3 | |
---|
4 | #ifndef INCL_LIST_H |
---|
5 | #define INCL_LIST_H |
---|
6 | |
---|
7 | /* |
---|
8 | $Log: not supported by cvs2svn $ |
---|
9 | Revision 1.1 1997/03/27 10:32:32 schmidt |
---|
10 | stream-io wrapped by NOSTREAMIO |
---|
11 | |
---|
12 | Revision 1.0 1996/05/17 11:06:32 stobbe |
---|
13 | Initial revision |
---|
14 | |
---|
15 | */ |
---|
16 | |
---|
17 | /*MAKEHEADER*/ |
---|
18 | #include "templates/config.h" |
---|
19 | |
---|
20 | #ifndef NOSTREAMIO |
---|
21 | #include <iostream.h> |
---|
22 | #endif /* NOSTREAMIO */ |
---|
23 | |
---|
24 | |
---|
25 | template <class T> |
---|
26 | class ListItem |
---|
27 | { |
---|
28 | private: |
---|
29 | ListItem * next; |
---|
30 | ListItem * prev; |
---|
31 | T * item; |
---|
32 | public: |
---|
33 | ListItem( const ListItem<T>& ); |
---|
34 | ListItem( const T&, ListItem<T>*, ListItem<T>* ); |
---|
35 | ListItem( T* , ListItem<T>* , ListItem<T>* ); |
---|
36 | ~ListItem(); |
---|
37 | ListItem<T>& operator= ( const ListItem<T>& ); |
---|
38 | ListItem<T>* getNext(); |
---|
39 | ListItem<T>* getPrev(); |
---|
40 | T& getItem(); |
---|
41 | #ifndef NOSTREAMIO |
---|
42 | void print ( ostream& ); |
---|
43 | #endif /* NOSTREAMIO */ |
---|
44 | friend class ListIterator<T>; |
---|
45 | friend class List<T>; |
---|
46 | }; |
---|
47 | |
---|
48 | template <class T> |
---|
49 | class List |
---|
50 | { |
---|
51 | private: |
---|
52 | ListItem<T> *first; |
---|
53 | ListItem<T> *last; |
---|
54 | int _length; |
---|
55 | public: |
---|
56 | List(); |
---|
57 | List( const List<T>& ); |
---|
58 | List( const T& ); |
---|
59 | ~List(); |
---|
60 | List<T>& operator= ( const List<T>& ); |
---|
61 | void insert ( const T& ); |
---|
62 | void insert ( const T&, int (*cmpf)( const T&, const T& ) ); |
---|
63 | void insert ( const T&, int (*cmpf)( const T&, const T& ), void (*insf)( T&, const T& ) ); |
---|
64 | void append ( const T& ); |
---|
65 | int isEmpty() const; |
---|
66 | int length() const; |
---|
67 | T getFirst() const; |
---|
68 | void removeFirst(); |
---|
69 | T getLast() const; |
---|
70 | void removeLast(); |
---|
71 | void sort ( int (*) ( const T&, const T& ) ); |
---|
72 | #ifndef NOSTREAMIO |
---|
73 | void print ( ostream & ) const; |
---|
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 */ |
---|