From 66000cde3e41429f5777a9a74a4593fe38e05bb0 Mon Sep 17 00:00:00 2001 From: sinoding Date: Tue, 3 May 2011 23:46:13 +0800 Subject: [PATCH] test --- ch25/design_pattern.cc | 43 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/ch25/design_pattern.cc b/ch25/design_pattern.cc index ef0b092..31d7110 100644 --- a/ch25/design_pattern.cc +++ b/ch25/design_pattern.cc @@ -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; +}; + + + +