lama_byterun/regression/test039.expr

33 lines
671 B
Text
Raw Normal View History

2019-09-29 02:47:07 +03:00
local n, t;
2018-05-16 16:50:36 +03:00
fun insert (t, x) {
case t of
2019-03-07 19:06:04 +03:00
Leaf -> return Node (x, Leaf, Leaf)
| Node (y, l, r) -> if x > y
then return Node (y, insert (l, x), r)
else return Node (y, l, insert (r, x))
2018-05-16 16:50:36 +03:00
fi
esac
}
fun find (t, x) {
case t of
2019-03-07 19:06:04 +03:00
Leaf -> return 0
| Node (y, l, r) -> if x == y then return 1
2019-04-02 19:51:46 +03:00
elif x > y then return find (l, x)
else return find (r, x)
fi
2018-05-16 16:50:36 +03:00
esac
}
n := read ();
2019-03-07 19:06:04 +03:00
t := insert (insert (insert (insert (Leaf, 5), 4), 6), 3);
2018-05-16 16:50:36 +03:00
write (find (t, 5));
write (find (t, 4));
write (find (t, 6));
write (find (t, 3));
write (find (t, 2));
write (find (t, 1))