daily pastebin goal
10%
SHARE
TWEET

Untitled

a guest Apr 16th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. mergesort list = if length list < 2
  2.                  then list
  3.                  else let half  = length list / 2
  4.                           left  = take half list  # take zoberie prvych half prvkov z listu a zahodi zvysok
  5.                           right = drop half list  # drop utrhne prvych half prvkov z listu a vrati zvysok
  6.                       in
  7.                           merge (mergesort left) (mergesort right)
  8.  
  9. merge [] right   = right
  10. merge left []    = left
  11. merge left right = if first left < first right                       # first vrati prvy prvok zoznamu
  12.                    then cons (first left) (merge (rest left) right)  # rest vrati zvysok zoznamu okrem prveho prvku
  13.                    else cons (first right) (merge left (rest right)) # cons prida prvok na zaciatok zoznamu
RAW Paste Data
Top