開発環境
- OS X Lion - Apple(OS)
- Emacs、BBEdit - Bare Bones Software, Inc. (Text Editor)
- プログラミング言語: MIT/GNU Scheme
計算機プログラムの構造と解釈(Gerald Jay Sussman(原著)、Julie Sussman(原著)、Harold Abelson(原著)、和田 英一(翻訳)、ピアソンエデュケーション、原書: Structure and Interpretation of Computer Programs (MIT Electrical Engineering and Computer Science)(SICP))の3(標準部品化力, オブジェクトおよび状態)、3.3(可変データでのモデル化)、3.3.2(キューの表現)の問題 3.21を解いてみる。
その他参考書籍
問題3.21
queueの表現はリストの最初と最後の対を指示する一対のポインタだから、Benの意図通りにキューが印字されない。
ということで、入力としてキューをとり、キューの中の項目の並びを印字する手続きprint-queueを定義。
コード(BBEdit)
sample.scm
(define (print-queue queue) (front-ptr queue)) (define q1 (make-queue))
入出力結果(Terminal, REPL(Read, Eval, Print, Loop))
1 ]=> (print-queue q1) ;Value: () 1 ]=> (insert-queue! q1 'a) ;Value 2: ((a) a) 1 ]=> (print-queue q1) ;Value 3: (a) 1 ]=> (insert-queue! q1 'b) ;Value 2: ((a b) b) 1 ]=> (print-queue q1) ;Value 3: (a b) 1 ]=> (delete-queue! q1) ;Value 2: ((b) b) 1 ]=> (print-queue q1) ;Value 4: (b) 1 ]=> (delete-queue! q1) ;Value 2: (() b) 1 ]=> (print-queue q1) ;Value: ()
0 コメント:
コメントを投稿