stack:

#include <iostream>
#include <vector>
#include <cstdlib>

template<class ElemType>
class Stack {
public:
  ElemType Top() const {
    int StackSize_ = data_.size();
    return data_[StackSize_ -1];
  }
  void Push(const ElemType &elem) {
    data_.push_back(elem);
  }
  void Pop() {
    data_.pop_back();
  }
  bool Empty() const {
    return data_.empty();
  }
  private:
    std::vector<ElemType> data_;
};

queue:

#include <iostream>
#include <vector>
#include <cstdlib>

template<class ElemType>
class Queue {
public:
  ElemType Front() const {
    return data_.front();
  }
  void Push(const ElemType &elem) {
    data_.push_back(elem);
  }
  void Pop() {
    for(int i=0 ; i!=data_.size()-1; i++){
      data_[i] = data_[i+1];
    }
    data_.pop_back();
  }
  bool Empty() const {
    return data_.empty();
  }
private:
  std::vector<ElemType> data_;
};

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 阿洲 的頭像
    阿洲

    阿洲程式天地

    阿洲 發表在 痞客邦 留言(0) 人氣()