이승중
가입: 2010년 6월 22일 올린 글: 561
|
올려짐: 2012년9월20일 16:58 주제: |
|
|
넵 3번 문제 템플릿은 작년것을 그대로 사용하도록 하겠습니다.
| 코드: | type heap = EMPTY | NODE of rank * value * heap * heap
and rank = int
and value = int
exception EmptyHeap
let rank h = match h with
| EMPTY -> -1
| NODE(r,_,_,_) -> r
let shake (x,lh,rh) =
if (rank lh) >= (rank rh)
then NODE(rank rh+1, x, lh, rh)
else NODE(rank lh+1, x, rh, lh)
let rec merge (* TODO *)
let findMin h = match h with
| EMPTY -> raise EmptyHeap
| NODE(_,x,_,_) -> x
let insert(x,h) = merge(h, NODE(0,x,EMPTY,EMPTY))
let deleteMin h = match h with
| EMPTY -> raise EmptyHeap
| NODE(_,x,lh,rh) -> merge (lh,rh)
|
(* TODO *) 부분만 채워넣으시면 됩니다.
empty가 -1임을 주의하시기 바랍니다. |
|