tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
21
Task/Set/Tcl/set.tcl
Normal file
21
Task/Set/Tcl/set.tcl
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package require struct::set
|
||||
|
||||
# Many ways to build sets
|
||||
set s1 [list 1 2 3 4]
|
||||
set s2 {3 4 5 6}
|
||||
struct::set add s3 {2 3 4 3 2}; # $s3 will be proper set...
|
||||
set item 5
|
||||
|
||||
puts "union: [struct::set union $s1 $s2]"
|
||||
puts "intersection: [struct::set intersect $s1 $s2]"
|
||||
puts "difference: [struct::set difference $s1 $s2]"
|
||||
puts "membership predicate: [struct::set contains $s1 $item]"
|
||||
puts "subset predicate: [struct::set subsetof $s1 $s2]"; # NB: not strict subset test!
|
||||
puts "equality predicate: [struct::set equal $s1 $s2]"
|
||||
|
||||
# Adding an element to a set (note that we pass in the name of the variable holding the set):
|
||||
struct::set include s3 $item
|
||||
# Removing an element from a set:
|
||||
struct::set exclude s3 $item
|
||||
# Getting the cardinality:
|
||||
puts "cardinality: [struct::set size $s3]
|
||||
Loading…
Add table
Add a link
Reference in a new issue