Appendix 5: C++ Classes for Searching

The following is a complete listing of the C++ integer set representation classes discussed in Column 13. The complete code can be found at this book’s web site.

class IntSetSTL {private:    set<int> S;public:    IntSetSTL(int maxelms, int maxval) { }    int size() { return S.size(); }    void insert(int t) { S.insert(t);}    void report(int *v)    {   int j = 0;        set<int>::iterator i;        for (i = S.begin(); i != S.end(); ++i)            v[j++] = *i;    }};

class IntSetArray {private:    int n, *x;public:    IntSetArray(int maxelms, int maxval)    {   x = new int[l + maxelms];        n = 0;        x[0] = maxval;    }    int size() { return ...

Get Programming Pearls, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.