Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
realfirst committed May 3, 2011
1 parent 8431690 commit 66000cd
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions ch25/design_pattern.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,47 @@ class IntSetArray : public IntSet {
int size, sizemax;
};

class Node {
public:
int value;
Node *next;
Node(int v, Node *n) : value(v), next(n) {}
};

class IntSetListInterator : public IntIterator {
public:
IntSetListInterator(Node *n) : current(n) {}
bool hasNext() {
return current;
}
int next() {
int r = current->value;
current = current->next;
return r;
}
private:
Node *current;
};

class IntSetList : public IntSet {
public:
IntSetList() : first(0) {}
~IntSetList() {
for (Node *n = first; n; n = n->next) {
delete n;
}
}
void add(int k) {
first = new Node(k, first);
}
IntIterator *iterator() const {
return new IntSetListInterator(first);
}
private:
Node *first;
};





0 comments on commit 66000cd

Please sign in to comment.