SICP 习题2.59 union-set操作
来源:互联网 发布:access数据库巡检 编辑:程序博客网 时间:2024/05/03 01:55
union-set操作的想法就是找出set1中set2里面没有的,set2中没有的和set2放在一起,就是union-set
第二种实现方法利用了adjoin,其实思想是一样的,
(union set1 set2) = (union (cdr set1) (adjoin (car set1) set2))
(define (element-of-set? x set) (cond ((null? set) false) ((equal? x (car set)) true) (else (element-of-set? x (cdr set)))))(define (adjoin x set) (if (element-of-set? x set) set (cons x set)))(define (intersection-set set1 set2) (cond ((or (null? set1) (null? set2)) '()) ((element-of-set? (car set1) set2) (cons (car set1) (intersection-set (cdr set1) set2))) (else (intersection-set (cdr set1) set2))))(define (union-set set1 set2) (cond ((null? set1) set2) ((not (element-of-set? (car set1) set2)) (cons (car set1) (union-set (cdr set1) set2))) (else (union-set (cdr set1) set2))))(define s1 '(1 2 3 4 5 6))(define s2 '(9 2 3 4 8 10))(newline)(display (intersection-set s1 s2))(newline)(display (union-set s1 s2))(define (union-set set1 set2) (cond ((null? set1) set2) (else (union-set (cdr set1) (adjoin (car set1) set2)))))(newline)(display (union-set s1 s2))
0 0
- SICP 习题2.59 union-set操作
- SICP 习题2.61~2.62 排序表示的adjoin和union-set函数
- SICP习题
- SICP 习题 (2.25)解题总结:列表的操作
- SICP 习题2.60 允许元素重复,重构集合操作
- SET操作符(UNION/UNION ALL/INTERSECT/MINUS)
- sicp 第一章习题试做
- sicp 第一章 习题
- sicp 2.2 习题
- sicp 2.3-2.5 习题
- SICP 部分习题答案
- SICP 习题答案1.1
- SICP 习题答案1.2
- SICP 习题答案1.3
- SICP 习题答案1.4
- SICP 习题答案1.5
- SICP 习题答案1.11
- sicp习题2.1
- 在centOS7 上安装MariaDB
- reids3 集群配置
- POJ1426-Find The Multiple-深度优先搜索BFS
- Mysql 查询缓存
- 自己生成网络后台接口并利用charles模拟Http请求和响应
- SICP 习题2.59 union-set操作
- codeforces 24 Game(数学构造)
- 解决Onenote不能同步
- HTML文档结点的遍历
- PO、VO、BO、DTO、POJO、DAO之间的关系
- 那些值得你试试的 Android 竞品分析工具
- JAVA面向对象-----java面向对象的六大原则
- 解决angular+spring boot的跨域问题
- JDK动态代理的常见问题