Stack.h
#ifndef STACK_H
#define STACK_H
#include
#include
#include
using namespace std;
class Stack
{
public:
Stack();
public:
bool push(const string &elem);
bool pop(string &elem);
bool peek(string &elem);
bool empty() const { return _stack.empty();}
bool full() const { return _stack.size()==_stack.max_size();}
int size() const { return _stack.size();}
bool find(const string &elem) const;
int count(const string &elem) const;
private:
vector _stack;
};
#endif // STACK_H
Stack.cpp
#include "Stack.h"
Stack::Stack()
{
}
bool Stack::push(const string &elem)
{
if(full()) return false;
_stack.push_back(elem);
return true;
}
bool Stack::pop(string &elem)
{
if(empty()) return false;
elem=_stack.back();
_stack.pop_back();
return true;
}
bool Stack::peek(string &elem)
{
if(empty()) return false;
elem=_stack.back();
return true;
}
bool Stack::find(const string &elem) const{
vector::const_iterator end_it=_stack.end();
return ::find(_stack.begin(),end_it,elem)!=end_it;
}
int Stack::count(const string &elem) const{
return ::count(_stack.begin(),_stack.end(),elem);
}
userProfile.h
#ifndef USERPROFILE_H
#define USERPROFILE_H
#include
#include
#include