私はハスケルを新しくしており、現在は樹木を扱っています。ここでは、ツリー内の要素を最大ヒープになるまでスワップする関数を作成したかったのです。これで、Heapsortアルゴリズムに使用します。これは私にこのエラー得maxheapの関数の解析エラー
data Bintree a = E | Tree (Bintree a) a (Bintree a) deriving(Eq, Ord, Show)
swaptree:: Bintree Int -> Bintree Int
swaptree (Tree E w E) = (Tree E w E)
swaptree (Tree E w (Tree lr x rr))|((max w x)==w)=(Tree E w (Tree lr x rr))
|((max w x)==x)=(Tree E x(swaptree(Tree lr w rr)))
|otherwise error "something went wrong or program is bad"
swaptree (Tree (Tree ll v rl) w E)|((max v w)==w)=(Tree (Tree ll v rl) w E)
|((max v w)==v)=(Tree (swaptree(Tree ll w rl)) v E)
|otherwise error "something went wrong or program is bad"
swaptree (Tree (Tree ll v rl) w (Tree lr x rr))|((max3 v w x)==w) = (Tree (Tree ll v rl) w (Tree lr x rr))
|((max v x)==x)=(Tree (Tree ll v rl) x (swaptree(Tree lr w rr)))
|((max v x)==v)=(Tree(swaptree(Tree ll w rl)) v (Tree lr x rr))
|otherwise error "something went wrong or program is bad"
swaptree':: Bintree Int -> Bintree Int
swaptree' (Tree E w E) = (Tree E w E)
swaptree' (Tree lub w rub) = (swaptree(Tree(swaptree lub) w (swaptree rub)))
:今
8:1: error:parse error (possibly incorrect indentation or mismatched brackets)
は、私はそれを見て、読んで、これは通常leSt
がin
なしで使用されて、起こることが、私はそれを使用していなかったので、私が持っていますこの問題を解決する方法はありません。 私のコードを改善するための助けやヒントをいただければ幸いです!
PS:私に哀悼の意を表してください。私が言ったように、私は現在、ハスケルで非常に悪いです。
あなたのソリューションははるかに優れています! –