Notice
Recent Posts
Recent Comments
Link
두근두근이야기
선택정렬(selection sort) in logo 본문
selection sort프로그램
to selectionsort :l
localmake "a (listtoarray :l) ;;변수를 {}배열로 변환한다
localmake "n (count :a) ;;count는 리스트의 개수를 반환한다.
localmake "n1 :n-1
local [i j min temp]
repeat :n1[make "i repcount ;;repcount 초기값 1, 반복 될 때마다 1씩 증가한다.
make "min :i ;; :i번째를 최소로 할당
repeat (:n-:i) [make "j sum :i repcount ;; :n-:i번 반복한다.
if lessp (item :j :a)(item :min :a) [make "min :j]] ;;a(j)<a(i)이면 j를 min으로 만든다
make "temp item :i :a ;;a(j)를 temp에 저장
setitem :i :a (item :min :a) ;;a(j)를 i자리에 넣는다
setitem :min :a :temp ;;a(i)를 j자리에 넣는다.
print (list :a repcount) ;;매 단계마다 배열의 과정을 출력
]
output arraytolist :a
end
'IT > IT ::컴퓨터시스템개론' 카테고리의 다른 글
바람개비 프로그램 in logo (0) | 2012.12.12 |
---|---|
두번째 과제(Programming) - Programming in Logo, Scratch, Processing, C (0) | 2012.11.15 |
두번째 과제(Programming) - Programming in Logo, Scratch, Processing, C ( 명세서 ) (0) | 2012.11.15 |
컴퓨터시스템개론 정기철교수님 (0) | 2012.10.14 |
첫번째 과제(essay) - 컴퓨터는 나에게 _________이다. (0) | 2012.09.16 |