我选择二进制搜索记录数组的索引ascasestudy对于我的研究生的研究由C++和haskell编写编写 C++代码和工作,现在我为haskell一个在haskell中通过冒泡排序在排序的索引中进行搜索
import Data.List
data BookInfo = Book Int String [String]
deriving (Show)
--Entering变量
entering :: Int String [String]-> Book
entering id name subject= Book id name subject
--make元组的阵列的IDEX
index :: [Book]->[Int]
index [m] = getID (Book id _ _ ) = id
main :: IO()
main = do
putStrLn "Please enter your book id,name,Subject"
Book inpStr <- getLine
putStrLn print r
- 冒泡使用地图
bubbleSort ::(Ord x) => [x] -> [x]
bubbleSort (x':xs) = if x>x' then x': bubbleSort(x:xs)
else
if x<x' then x: bubbleSort(x':xs)
else
x: bubbleSort(X':xs)
bubble ::[a] -> [a]
bubble [a] = map bubbleSort [a]
--make指数为阵列
indexsort(ord a)::[int]->[Int]
indexsort a=bubble a
--make元组的列表
addBooks2List Book->[Book]->[Book]
addBooks2List b m=b:entering b':m
--binarysearch
binarysearch [Int]->Int->Int->Int->Int
a=bubble x
binaryseach a i m j=
let u=(i+m)/2
if a[u]=j then u
if a[u]>j then binaryseach a i u-1 j
else
if a[u]<j then binarysearch a u+1 m j
if i=m "Not found"
--printing具有搜索ID
print::Int->Book
print r= Book r y z
r=binaryseach m 0 (length m)
它在8犯了一个错误的元组:输入3解析错误“进入”这个错误是什么意思?以及我如何纠正它?
谢谢你的帮助 – 2012-07-16 09:05:20