See chapter 12 (and bits of 13 and 14).
Simple example [ 15set.cpp ]
Rule 0: no duplicates in a set.
If you want multiple occurrences.... use a 'multiset'.
Set Operations in Math
Operations inspired by C bit operations + Pascal and Ada sets.
Book page 267
C and C++ bit operations: &, |, ~, and ^
His version is close to the STL <bitset> [ bitsets ]
application: Eratosthenes sieve.
. . . . . . . . . ( end of section Bitsets) <<Contents | Index>>
(spell checking): Also see pages 126 and 129
error on p273: set<int> should be set<string>
(spelling correction): On page 274 'transpositions' should be 'transposition'
STL version is very similar. [ sets ]
Notice the reversed iterators: rbegin() and rend() for backwards through a set of items.
p278-290 Set operations: includes, union, intersection, ...
p279 Creating new sets
Uses a Binary Search Trees.
What is a Binary Tree?
What is a Binary Search Tree?
UML handout shows the physical structure. [ ch12set.gif ]
On pages 283, change 'Child.size' to 'Child->size' twice.
A more complex node class + the iterators that traverse trees in various ways from the next chapter.
Page 285: error in while loop: should include "&& (first != end())"
Page 286: error in 'if(newElement'. Should be 'if(newNode->value'
Page 288: missing 'if(result)' in front of 'result->parent'.
Botting's law of pointer sanity: if you don't know for certain sure that pointer p points at something do not star or arrow it.
Uses iterators from chapter 13
Notice that the set algorithms tend to have a structure like Section 12.6.1: A Balanced Line Merge.
How balanced is a search tree? In the worst case a set
like Budd's is a O(n) insert/find/delete structure. Can
we beat this?
You Betya! See Chapter 14... and then lookout for hashing methods.
Sets: A catch-all container -- easy to insert items, easy to
find items, and easy to erase items.
. . . . . . . . . ( end of section Sets) <<Contents | Index>>
project 3+Quiz 3
plus lecture on Ch14 Searching