我有一个 TreeVertex 类:
// TreeVertex.h
#ifndef __TREEVERTEX__
#define __TREEVERTEX__
#include <list>
using namespace std;
class TreeVertex {
public:
TreeVertex(list<int>, TreeVertex* = NULL);
list<int> getItemset();
private:
list<int> Itemset;
TreeVertex * Parent;
TreeVertex * LeftChild;
TreeVertex * RightSibling;
};
#endif // __TREEVERTEX__
// TreeVertex.cpp
#include "TreeVertex.h"
TreeVertex::TreeVertex(list<int> Itemset, TreeVertex* Parent) : Itemset(Itemset), Parent(Parent), LeftChild(NULL),
RightSibling(NULL) { }
list<int>
TreeVertex::getItemset() {
return Itemset;
}
和这样的主要功能:
#include <iostream>
#include "TreeVertex.h"
using namespace std;
int main (int argc, const char ** const argv)
{
list<int> tmpList1;
tmpList1.push_back(1);
TreeVertex * tmpTreeVert1 = new TreeVertex(tmpList1);
list<int> tmpList2;
tmpList2.push_back(2);
TreeVertex * tmpTreeVert2 = new TreeVertex(tmpList2);
list<int> newVertItemset;
newVertItemset.push_back(tmpTreeVert1->getItemset().front());
newVertItemset.push_back(tmpTreeVert2->getItemset().front());
cout << newVertItemset.front() << " " << newVertItemset.back() << endl;
TreeVertex * newTreeVert = new TreeVertex(newVertItemset);
cout << newTreeVert->getItemset().front() << " " << newTreeVert->getItemset().back() << endl;
for (list<int>::iterator it = newTreeVert->getItemset().begin(); it != newTreeVert->getItemset().end(); ++it) {
cout << (*it) << " ";
}
cout << endl;
cout << newTreeVert->getItemset().size() << endl;
return 0;
}
输出如下所示:
1 2
1 2
2
2
最后一个输出(第一个“2”)的旁边应该是“1 2”,就像其他输出一样。
任何想法为什么迭代器不遍历第一个元素?
谢谢。