% Here is the beginning of a driver program. You can use it or not, % as you see fit. Feel free also to change it if you like. import Set in "set.tu", SimpleObject in "simple.tu" var s : ^Set new s put "----- BUILDING a set of whatever size you like -----" put "The elements will have consecutive integer values." var n : int put "How big a set do you want? " .. get n var list : array 1 .. n of ^SimpleObject for i : 1 .. n var p : ^SimpleObject new p p -> setValue (i) list (i) := p end for s -> buildFromList (list, n) put skip, "The set is built. Here's what it looks like, as a tree:" s -> printasTree put "Using an array, I have separately kept track of the ", n, " elements in your tree." put "The i-th element in my array is a SimpleObject with value i." put skip, "------ DELETING from the set ---" put "You can now delete elements from the tree." loop var wh : int put "Which element? (0 to exit) > " .. get wh exit when wh = 0 s -> removeElement (list (wh)) put "The revised tree:" s -> printasTree end loop % Note: The following code will always create an empty subset % because you have to implement AddElement for Subset to work. % Once you have AddElement, this code will work. See how we % pass a "filter" function into Subset. put skip, "----- Creating a SUBSET -----" put "It will contain only odd elements of the original set." function odd (thing : ^SimpleObject) : boolean result thing -> valueOf mod 2 = 1 end odd var sub : ^Set sub := s -> Subset (odd) put "Here's the subset, as a tree:" sub -> printasTree put skip, "All done. Bye!"