source: git/factory/templates/ftmpl_list.h @ 0f2e64

spielwiese
Last change on this file since 0f2e64 was 0f2e64, checked in by Gerhard Pfister <pfister@…>, 22 years ago
* hannes/GP/michael: factory debug, Factorize git-svn-id: file:///usr/local/Singular/svn/trunk@5489 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 2.7 KB
Line 
1/* emacs edit mode for this file is -*- C++ -*- */
2/* $Id: ftmpl_list.h,v 1.6 2001-06-18 08:44:37 pfister 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
13template <class T>
14class ListIterator;
15
16template <class T>
17class List;
18
19template <class T>
20class ListItem
21{
22private:
23    ListItem * next;
24    ListItem * prev;
25    T * item;
26public:
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
42template <class T>
43class List
44{
45private:
46    ListItem<T> *first;
47    ListItem<T> *last;
48    int _length;
49public:
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    friend ostream& operator<< <>( ostream & os, const List<T> & l );
71};
72
73#ifndef NOSTREAMIO
74template <class T>
75ostream& operator<< ( ostream & os, const List<T> & l );
76#endif /* NOSTREAMIO */
77
78template <class T>
79class ListIterator {
80private:
81    List<T> *theList;
82    ListItem<T> *current;
83public:
84    ListIterator();
85    ListIterator( const ListIterator<T>& );
86    ListIterator( const List<T>& );
87    ~ListIterator();
88    ListIterator<T>& operator = ( const ListIterator<T>& );
89    ListIterator<T>& operator = ( const List<T>& );
90    T& getItem() const;
91    int hasItem();
92    void operator++();
93    void operator--();
94    void operator++( int );
95    void operator--( int );
96    void firstItem();
97    void lastItem();
98    void insert( const T& );
99    void append( const T& );
100    void remove( int moveright );
101};
102
103template <class T>
104List<T> Union ( const List<T>&, const List<T>& );
105
106template <class T>
107List<T> Difference ( const List<T>&, const List<T>& );
108
109template <class T>
110List<T> Union ( const List<T>&, const List<T>&, int (*cmpf)( const T&, const T& ), void (*insf)( T&, const T& ) );
111
112template <class T>
113T prod ( const List<T>& );
114
115#endif /* ! INCL_LIST_H */
Note: See TracBrowser for help on using the repository browser.