您好,我正在使用 Haskell Gloss创建二叉树图片并模拟值的插入。
我能够创建一个draw
函数来创建树的图片并且它工作正常。
问题在于创建模拟。在树上的每个值插入之后,我有一个包含所有树的列表,并希望- 函数在过去的某个时间选择列表update
位置的树,i
并不断切换列表中每个树生成的图片i
。
有没有办法做到这一点?
drawTree::(Show a)=>BTree a->Picture
updateTree :: ViewPort->Float->[BTree a]->[BTree a]
updateTree _ dt list=[list!!toInt dt]
main::IO()
main = do
--receives all values to be inserted
values <- getLine
let list = read values :: [Int]
--temp is a list that stores all the tree generated in each insertion
let temp =insertValues list Leaf
--stores the tree contained in the last inserction
let tree = last temp
--stores the tree after the first insertion
let fir=first temp
simulate window background fps [fir] drawTree updateTree