3636namespace Java {
3737 namespace Util {
3838 template <typename E>
39- class Stack : public virtual Collection<E> {
39+ class Stack {
4040
4141 private:
4242 std::stack<E> original;
@@ -51,99 +51,51 @@ namespace Java {
5151 * @return boolean
5252 */
5353 boolean empty () {
54- int size = this ->original .size ();
55-
56- if (size != 0 ) {
57- return TRUE ;
54+ if (this ->original .size () == 0 ) {
55+ return false ;
5856 }
59- return FALSE ;
57+ return true ;
6058 }
6159
6260 /* *
63- * Stack peek - return the top element
64- *
65- * @param original
66- */
67- E peek () {
68- return this ->original .top ();
69- }
61+ *Looks at the object at the top of this stack without removing it from the stack.
62+ * @return E
63+ */
64+ E peek () {
65+ E e;
66+ if (this ->original .size () > 0 ) {
67+ e = this ->original .top ();
68+ }
69+ return e;
70+ }
7071
71- /* *
72- * Stack pop - return the top element and remove it
73- *
74- * @param original
75- */
72+ /* *
73+ * Removes the object at the top of this stack and returns that object as the value of this function.
74+ * @return E
75+ */
7676 E pop () {
77- E result = this ->original .top ();
78- this ->original .pop ();
79- return result;
77+ E e;
78+ if (this ->original .size () > 0 ) {
79+ e = this ->original .top ();
80+ this ->original .pop ();
81+ }
82+ return e;
8083 }
8184
82- /* *
83- * Stack push - Push new element
84- *
85- * @param original
86- */
85+ /* *
86+ * Pushes an item onto the top of this stack
87+ * @param item
88+ * @return E
89+ */
8790 E push (const E &item) {
8891 this ->original .push (item);
89- }
90-
91- /* *
92- * Stack search - search the object in Stack, return the 1-based position from the top, -1 if can not find the object in Stack
93- *
94- * @param original
95- */
96- int search (const E &o) {
97- int position = 0 ;
98- int i;
99- for (i = 0 ; i < this ->original .size (); i++) {
100- if (i == o) {
101- return i;
102- }
103- }
104- return -1 ;
105- }
106-
107- boolean add (E &e) {
108- this ->original .push (e);
92+ return item;
10993 }
11094
11195 /* *
112- * Size of Stack
113- *
114- * @param original
115- */
116- int size () {
117- return this ->original .size ();
118- }
119-
120- boolean addAll (Collection<E> &c) {
121- }
122- void clear () {
123- }
124- boolean contains (Object &o) const {
125- }
126- boolean equals (const Object &o) const {
127- }
128- int hashCode () const {
129- }
130- boolean isEmpty () const {
131- }
132- Iterator<E> &iterator () const {
133- }
134- boolean remove (Object &o) {
135- }
136- boolean removeAll (Collection<Object> &c) {
137- }
138- boolean removeIf (Java::Util::Function::Predicate<E> &filter) {
139- }
140- boolean retainAll (Collection<Object> &c) {
141- }
142-
143- int size () const {
144- return this ->original .size ();
145- }
146-
96+ * Don't support this method
97+ */
98+ // int search(Object &o);
14799 };
148100 }
149101}
0 commit comments