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