Scheme
Programing 미분류 :
2008. 4. 22. 10:18
반응형
(define stack '())
(define (Sdisplay)
stack
)
(define (push x)
(set! stack (cons x stack))
)
(defins (pop)
(display (car stack))
(set! stack(cdr stack))
)
;custom-delete(with loop)
(define tmplst '())
(define (c-dl! item lst)
(let loop ((left-lst lst) (right-lst '()))
(cond
((equal? item (car lst))
(append right-lst (cdr left-lst)))
(else (loop (cdr left-lst)
(append right-lst (list (car left-lst)))
);loop
);else
);cond
);let
);define
(define tmplst '())
(define (c-dl! item lst)
(let loop ((left-lst lst) (right-lst '()))
(cond
((equal? item (car lst))
(append right-lst (cdr left-lst)))
(else (loop (cdr left-lst)
(append right-lst (list (car left-lst)))
);loop
);else
);cond
);let
);define
;select sort
(define (sel-sort lst)
(let loop ((source-list lst) (dest-list '()))
(cond
((equal? source-list '()) dest-list)
(else
(set! dest-list (append dest-list (list (apply min source-list))))
(loop (c-d! (apply min source-list) source-list) dest-list)
);else
);cond
);let
);define
(define (sel-sort lst)
(let loop ((source-list lst) (dest-list '()))
(cond
((equal? source-list '()) dest-list)
(else
(set! dest-list (append dest-list (list (apply min source-list))))
(loop (c-d! (apply min source-list) source-list) dest-list)
);else
);cond
);let
);define
(define (e-q s1 s2)
(let loop( (buf1 s1) (buf2 s2) )
(cond
((and (null? buf1) (null? buf2)) #T)
((> (length buf1)(length buf2)) '())
((< (length buf1)(length buf2)) '())
(
(equal? (length(car buf1)) (length(car buf2))
)
(loop (cdr buf1)(cdr buf2))
)
)
)
)
(let loop( (buf1 s1) (buf2 s2) )
(cond
((and (null? buf1) (null? buf2)) #T)
((> (length buf1)(length buf2)) '())
((< (length buf1)(length buf2)) '())
(
(equal? (length(car buf1)) (length(car buf2))
)
(loop (cdr buf1)(cdr buf2))
)
)
)
)
;insert sort
(define tmplst '())
(define (insert-sort lst)
(let loop ((source-list lst) (dest-list '()))
(cond
((equal? source-list '()) dest-list)
((equal? dest-list '())
(set! dest-list
(append tmplst (list (car source-list))))
(set! tmplst '())
(loop (cdr source-list) dest-list))
((> (car source-list) (car dest-list))
(set! tmplst
(append tmplst (list (car dest-list))))
(loop source-list (cdr dest-list)))
(else
(set! dest-list
(append tmplst (cons (car source-list) dest-list)))
(set! tmplst '())
(loop (cdr source-list) dest-list))
);cond
);let
);define
(define tmplst '())
(define (insert-sort lst)
(let loop ((source-list lst) (dest-list '()))
(cond
((equal? source-list '()) dest-list)
((equal? dest-list '())
(set! dest-list
(append tmplst (list (car source-list))))
(set! tmplst '())
(loop (cdr source-list) dest-list))
((> (car source-list) (car dest-list))
(set! tmplst
(append tmplst (list (car dest-list))))
(loop source-list (cdr dest-list)))
(else
(set! dest-list
(append tmplst (cons (car source-list) dest-list)))
(set! tmplst '())
(loop (cdr source-list) dest-list))
);cond
);let
);define
(define queue '())
(define tqueue '())
(define (insert item)
(set! queue(append queue (cons item'())))
)
(define (remove) (set! tqueue queue)
(set! queue (cdr queue))
(car tqueue)
)
(define tqueue '())
(define (insert item)
(set! queue(append queue (cons item'())))
)
(define (remove) (set! tqueue queue)
(set! queue (cdr queue))
(car tqueue)
)
반응형
'Programing 미분류' 카테고리의 다른 글
Fixed Point Coding (0) | 2009.02.15 |
---|---|
Scheme (0) | 2008.03.05 |
HMD 와 블루투스 및 기울기 센서를 이용한 3D 게임 (0) | 2008.01.02 |