scheme 模拟queue
[code 1] shows a implementation of queue. The function enqueue! returns a queue in that the obj is added at the last of the queue. The function dequeue!removes the first item from the queue and return the first item.
[code 1]
(define (make-queue)
(cons '() '())) (define (enqueue! queue obj)
(let ((lobj (cons obj '())))
(if (null? (car queue))
(begin
(set-car! queue lobj)
(set-cdr! queue lobj))
(begin
(set-cdr! (cdr queue) lobj)
(set-cdr! queue lobj)))
(car queue))) (define (dequeue! queue)
(let ((obj (car (car queue))))
(set-car! queue (cdr (car queue)))
obj))
(define q (make-queue))
;Value: q (enqueue! q 'a)
;Value 12: (a) (enqueue! q 'b)
;Value 12: (a b) (enqueue! q 'c)
;Value 12: (a b c) (dequeue! q)
;Value: a q
;Value 13: ((b c) c) 实际上
(make-queue q 'a)
后输出q为:
((a) a)
(enqueue! q 'b)
(a b)
> q
((a b) b)
http://www.shido.info/lisp/scheme_asg_e.html
scheme 模拟queue的更多相关文章
- 1. 模拟Queue
package com.gf.conn009; import java.util.LinkedList; import java.util.concurrent.atomic.AtomicIntege ...
- wait , notify 模拟 Queue
package com.itdoc.multi.sync009; import java.util.LinkedList; import java.util.concurrent.TimeUnit; ...
- Codeforces Round #366 (Div. 2) C 模拟queue
C. Thor time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- CF #366 DIV2 C. Thor 模拟 queue/stack降低复杂度
C. Thor time limit per test 2 seconds memory limit per test 256 megabytes input standard input outpu ...
- 模拟Queue(wait/notify)
BlockingQueue:顾名思义,首先它是一个队列,并且支持阻塞的机制,阻塞的放入和得到数据.我们要实现LinkedBlockingQueue下面的两个方法put和take. put(anObje ...
- 用数组模拟STL中的srack(栈)和queue(队列)
我们在理解stack和queue的基础上可以用数组来代替这两个容器,因为STL中的stack和queue有可能会导致程序运行起来非常的慢,爆TLE,所以我们使用数组来模拟他们,不仅可以更快,还可以让代 ...
- Team Queue(STL练习题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1387 Team Queue Time Limit: 2000/1000 MS (Java/Others ...
- new、delete、以及queue类
本来以为很容易的,结果还是写了我两个小时. 用指针模拟queue类,再加上类,各种错误,总算是解决掉了-- #include<iostream> #include<cstdlib&g ...
- 团体队列 UVA540 Team Queue
题目描述 有t个团队的人正在排一个长队.每次新来一个人时,如果他有队友在排队,那么新人会插队到最后一个队友的身后.如果没有任何一个队友排队,则他会被排到长队的队尾. 输入每个团队中所有队员的编号,要求 ...
随机推荐
- (转载):() { :|:& }; : # <-- 打开终端,输入这个,回车.你看到了什么??
代码::() { :|:& }; : 为什么这个东西会让你的系统死掉???有人执行了然后问我 让我们来分析一下这段代码,我改一下格式,但内容是一样的 代码::() # 定义一个叫“:”的过程 ...
- shell下有操作json对象的库
http://kernelpanic.im/blog/2012/03/08/shell-manipulate-json/ Json.org推荐了两个:Jshon和JSON.sh 其中JSON.sh是完 ...
- shell编程笔记(1)
shell编程: 编译器,解释器 编程语言:机器语言.汇编语言.高级语言 静态语言:编译型语言 强类型(变量) 事先转换成可执行格式 C.C++.JAVA.C# ...
- ubuntu14.04 安装 StudioZend12
到官网下载:http://www.zend.com/en/products/studio/downloadsLinux-64位:http://downloads.zend.com/studio-ecl ...
- VS 项目(c#)引用了 DLL文件,也写了Using,但是编译时提示:未能找到类型或命名空间名称
1. 在项目上点右键-->属性-->应用程序-->目标框架-->修改为.NET Framework 4. 而我原来的设置是.NET Framework 4 Client Pro ...
- Unity Navigation面板了解
上次讲解了下Navigation的简单使用, 这次来看看Navigation面板的一些参数 NavigationStatic 勾选后表示该对象参与导航网格的烘培. OffMeshLink Genera ...
- servlet获得完整路径
request.getQueryString() request.getParameterMap() request.getParameterNames() 在servlet中GET请求可以通过Htt ...
- HTML\Script 去除关键字
以下是引用片段: ----- /**/ /// <summary> /// 去除HTML标记 /// </summary> /// <param name="N ...
- C#使用seleium实现一个自动登录器
1.http://docs.seleniumhq.org/ 下载seleium包 2.新建一个C#项目,比如控制台,引用seleium包中的dll using System; using System ...
- -canOpenURL: failed for URL
这在 Xcode 6.4 + iOS 8 时,是不会有的情况,原因是[为了强制增强数据访问安全, iOS9 默认会把所有从NSURLConnection . CFURL . NSURLSession发 ...