/* Stack.H: simple stack implementation */

#ifndef _XRML_STACK_H_
#define _XRML_STACK_H_

#include "Array.H"

namespace xrml {

template<class T>
class stack: public array<T> {
public:
  inline stack<T>() { init(0, 0); };
  inline stack<T>(int len) { init(len, 0); };
  inline void push (const T& elem) { append(elem); };
  inline T& pop(void) { return operator[](--size); };
  inline T& top(void) { return operator[](size-1); };

  bool remove(const T& elem)
  {
    bool elem_removed = false;
    for (int i=0; i<size; i++) {
      if (s[i] == elem) {
	for (int j=i; j<size-1; j++)
	  s[j] = s[j+1];
	size--;
	elem_removed = true;
      }
    }
    return elem_removed;
  }
};

} // namespace xrml

#endif /* _XRML_STACK_H_ */
