我已经实现了我自己的双向链表,它具有模板节点。通过这个节点,我已经存储了我自己的对象(Play),它得到了 gunctions,并且我为我的列表创建了一个迭代器。
for(DLL<Play>::iterator itr=PlayList.begin(); itr!=PlayList.end(); itr++)
if(offense==*how do I access this*getoTeam()){
这是我的节点和迭代器代码:
template<class T>
class node{
public:
T data;
node *next, *prev;
node(const T& t, node<T> *n = 0, node<T> *p = 0) {data=t; next=n; prev=p;}
node() {next = prev = 0;}
};
template<typename T>
class Iterator{
public:
Iterator(node<T> *np=0) : nodePtr(np) {}
T& operator*() const {return nodePtr->data;}
Iterator<T> &operator++(){
nodePtr = nodePtr->next;
return *this;
}
Iterator<T> operator++(int){
Iterator<T> Temp(nodePtr);
nodePtr = nodePtr->next;
return Temp;
}
bool operator==(Iterator<T> i) { return nodePtr == i.nodePtr; }
bool operator!=(Iterator<T> i) { return nodePtr != i.nodePtr; }
private:
node<T> * nodePtr;
};
我不知道我将如何访问它。如果您也能解释原因,我将不胜感激。
谢谢。
以防万一,这是我的 Play 对象:
#ifndef PLAY_H_INCLUDED
#define PLAY_H_INCLUDED
#include <string>
class Play
{
private:
int m_quarter;
int m_minutes;
std::string oTeam;
std::string dTeam;
int m_down;
int m_yardToGO;
int m_startLoc;
int playDesc;
std::string wholePlay;
public:
int getQuarter();
int getMinutes();
std::string getoTeam();
std::string getdTeam();
int getDown();
int getYard();
int getStartLoc();
int getPlayDesc();
std::string getwholePlay();
Play(int quarter, int minutes, std::string offense, std::string defense, int dwn, int ytg, int start, int desc, std::string play);
~Play();
Play parse(std::string toParse);
std::string findPlay(std::string playDesc);
};
#endif // PLAY_H_INCLUDED