// // Title: Concepts of Programming Languages // Number: CAS CS 320 // Semester: Fall 2012 // Class Time: TR 12:30-2:00 // Instructor: Hongwei Xi (hwxiATcsDOTbuDOTedu) // Teaching Fellow: Alex Ren (arenATcsDOTbuDOTedu) // (* // // Assignment #3 // Due Friday, February 8, 2013 at 11:59pm // *) (* ****** ****** *) // // Problem 1: 30 points // (* ****** ****** *) #include "BUCASCS320-3.hats" (* ****** ****** *) staload "assignment3_avltree.sats" (* ****** ****** *) implement{a} tree_size (xs) = ( // // Please give your implementation here: // ) implement{a} tree_height (xs) = ( // // Please give your implementation here: // ) (* ****** ****** *) (* fun abs (x: int): int = if x >= 0 then x else ~x *) implement{a} isAVL (xs) = let in // case+ xs of | tree_nil () => true | tree_cons (xs1, _, xs2) => if isAVL (xs1) then ( if isAVL (xs2) then let val h1 = tree_height (xs1) val h2 = tree_height (xs2) in if abs(h1-h2) <= 1 then true else false end else false ) else false // end of [if] // end of [tree_cons] // end // end of [isAVL] (* ****** ****** *) implement{a} isAVL2 (xs) = ( // // Please give your implementation here: // ) (* ****** ****** *) implement main () = let val t0 = tree_nil () // val t1 = tree_cons (t0, 1, t0) // val t2 = tree_cons (t1, 2, t1) // val t3 = tree_cons (t1, 3, t2) // val t4 = tree_cons (t3, 4, t3) val () = assertloc (isAVL2 (t4)) // val t5 = tree_cons (t2, 5, t4) val () = assertloc (~isAVL2 (t5)) // in // nothing end // end of [main] (* ****** ****** *) (* end of [assignment3_avltree.dats] *)