2014-08-29 07:52:33 -07:00
|
|
|
/**
|
|
|
|
* @file fl_stack.h
|
|
|
|
* @brief Fixed-length stack
|
|
|
|
*
|
|
|
|
* @date Jul 9, 2014
|
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2014
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef FL_STACK_H_
|
|
|
|
#define FL_STACK_H_
|
|
|
|
|
|
|
|
template<typename T, int MAXSIZE>
|
|
|
|
class FLStack {
|
|
|
|
public:
|
|
|
|
FLStack();
|
|
|
|
void push(T value);
|
2014-10-03 12:05:03 -07:00
|
|
|
void reset();
|
2014-08-29 07:52:33 -07:00
|
|
|
T pop();
|
|
|
|
int size();
|
|
|
|
bool isEmpty();
|
|
|
|
private:
|
|
|
|
int index;
|
|
|
|
T values[MAXSIZE];
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T, int MAXSIZE>
|
|
|
|
FLStack<T, MAXSIZE>::FLStack() {
|
2014-10-03 12:05:03 -07:00
|
|
|
reset();
|
2014-08-29 07:52:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T, int MAXSIZE>
|
|
|
|
bool FLStack<T, MAXSIZE>::isEmpty() {
|
|
|
|
return index == 0;
|
|
|
|
}
|
|
|
|
|
2014-10-03 12:05:03 -07:00
|
|
|
template<typename T, int MAXSIZE>
|
|
|
|
void FLStack<T, MAXSIZE>::reset() {
|
|
|
|
index = 0;
|
|
|
|
}
|
|
|
|
|
2014-08-29 07:52:33 -07:00
|
|
|
template<typename T, int MAXSIZE>
|
|
|
|
void FLStack<T, MAXSIZE>::push(T value) {
|
|
|
|
values[index++] = value;
|
|
|
|
}
|
|
|
|
|
2014-10-03 12:05:03 -07:00
|
|
|
template<typename T, int MAXSIZE>
|
|
|
|
T FLStack<T, MAXSIZE>::pop() {
|
|
|
|
return values[--index];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-29 07:52:33 -07:00
|
|
|
template<typename T, int MAXSIZE>
|
|
|
|
int FLStack<T, MAXSIZE>::size() {
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* FL_STACK_H_ */
|