1
|
1 // This may look like C code, but it is really -*- C++ -*- |
|
2 /* |
|
3 Copyright (C) 1988 Free Software Foundation |
|
4 written by Doug Lea (dl@rocky.oswego.edu) |
|
5 |
|
6 This file is part of the GNU C++ Library. This library is free |
|
7 software; you can redistribute it and/or modify it under the terms of |
|
8 the GNU Library General Public License as published by the Free |
|
9 Software Foundation; either version 2 of the License, or (at your |
|
10 option) any later version. This library is distributed in the hope |
|
11 that it will be useful, but WITHOUT ANY WARRANTY; without even the |
|
12 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
|
13 PURPOSE. See the GNU Library General Public License for more details. |
|
14 You should have received a copy of the GNU Library General Public |
|
15 License along with this library; if not, write to the Free Software |
|
16 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
|
17 */ |
|
18 |
|
19 |
|
20 #ifndef _SLStack_h |
|
21 #ifdef __GNUG__ |
|
22 //#pragma interface |
|
23 #endif |
|
24 #define _SLStack_h 1 |
|
25 |
|
26 #include "SLList.h" |
|
27 #include "Stack.h" |
|
28 |
|
29 template <class T> |
|
30 class SLStack : public Stack<T> |
|
31 { |
|
32 private: |
|
33 SLList<T> p; |
|
34 |
|
35 public: |
|
36 SLStack (void); |
|
37 SLStack (const SLStack<T>& s); |
|
38 ~SLStack (void); |
|
39 |
|
40 void operator = (const SLStack<T>&); |
|
41 |
|
42 void push (const T& item); |
|
43 T pop (void); |
|
44 T& top (void); |
|
45 void del_top (void); |
|
46 |
|
47 int empty (void); |
|
48 int full (void); |
|
49 int length (void); |
|
50 |
|
51 void clear (void); |
|
52 |
|
53 int OK (void); |
|
54 }; |
|
55 |
|
56 template <class T> |
|
57 inline SLStack<T>::SLStack (void) : p () { } |
|
58 |
|
59 template <class T> |
|
60 inline SLStack<T>::SLStack (const SLStack<T>& a) : p (a.p) { } |
|
61 |
|
62 template <class T> |
|
63 inline SLStack<T>::~SLStack (void) { } |
|
64 |
|
65 template <class T> |
|
66 inline void |
|
67 SLStack<T>::push (const T& item) |
|
68 { |
|
69 p.prepend (item); |
|
70 } |
|
71 |
|
72 template <class T> |
|
73 inline T |
|
74 SLStack<T>::pop (void) |
|
75 { |
|
76 return p.remove_front (); |
|
77 } |
|
78 |
|
79 template <class T> |
|
80 inline T& |
|
81 SLStack<T>::top (void) |
|
82 { |
|
83 return p.front (); |
|
84 } |
|
85 |
|
86 template <class T> |
|
87 inline void |
|
88 SLStack<T>::del_top (void) |
|
89 { |
|
90 p.del_front (); |
|
91 } |
|
92 |
|
93 template <class T> |
|
94 inline void |
|
95 SLStack<T>::operator = (const SLStack<T>& s) |
|
96 { |
|
97 p = s.p; |
|
98 } |
|
99 |
|
100 template <class T> |
|
101 inline int |
|
102 SLStack<T>::empty (void) |
|
103 { |
|
104 return p.empty (); |
|
105 } |
|
106 |
|
107 template <class T> |
|
108 inline int |
|
109 SLStack<T>::full (void) |
|
110 { |
|
111 return 0; |
|
112 } |
|
113 |
|
114 template <class T> |
|
115 inline int |
|
116 SLStack<T>::length (void) |
|
117 { |
|
118 return p.length (); |
|
119 } |
|
120 |
|
121 template <class T> |
|
122 inline int |
|
123 SLStack<T>::OK (void) |
|
124 { |
|
125 return p.OK (); |
|
126 } |
|
127 |
|
128 template <class T> |
|
129 inline void |
|
130 SLStack<T>::clear (void) |
|
131 { |
|
132 p.clear (); |
|
133 } |
|
134 |
|
135 #endif |