- 69 名前:デフォルトの名無しさん mailto:sage [2009/10/04(日) 18:57:28 ]
- haskell.g.hatena.ne.jp/taninsw/の
qsort[]=[] qsort(x:xs)=qsort larger ++ [x]++ qsort smaller where smaller = [a|a<-xs,a <=x] larger = [b|b<-xs,b>x] What would be the effect of replacing <= by < in the definiton of qsort? Hint:consider the example qsort[2,2,3,1] 改変されたqsortをqsort'だと仮定する qsort[2,2,3,1]=qsort [2,1] ++[2]++qsort [3]=(qsort[1]++[2]++qsort[])++[2]++(qsort[]++[3]++qsort[]) =((qsort[]++[1]++qsort[])++[2]++[])++[2]++([]++[3]++[]) =[]+[1]+[]+[2]+[]+[]+[2]+[]+[3]+[]=[1,2,2,3] qsort'[2,2,3,1]=qsort [1] ++ [2] ++ qsort[3]=qsort[]++[1]++qsort[]++[2]++qsort[]++[3]++qsort[] =[]++[1]++[]++[2]++[]++[3]++[] つまり、同じ値が複数あるときは、ひとつを残して消えてしまう。 −−−−−−−−− で、値が消えないんだけど文意を取り違えているのかどうなんだろう 消える様に改変しろなのかな? smaller = [a|a<-xs,a <=x]をsmaller = [a|a<-xs,a <x]すると消えるけど
|

|