Revision 27bfa7b1b87d081df9d714144cf1e6aae2b87b19 authored by Damien Doligez on 19 August 2004, 12:52:17 UTC, committed by Damien Doligez on 19 August 2004, 12:52:17 UTC
git-svn-id: http://caml.inria.fr/svn/ocaml/version/3.08@6606 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
1 parent 510ea35
tagged-quicksort.cmm
(***********************************************************************)
(* *)
(* Objective Caml *)
(* *)
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
(* *)
(* Copyright 1996 Institut National de Recherche en Informatique et *)
(* en Automatique. All rights reserved. This file is distributed *)
(* under the terms of the Q Public License version 1.0. *)
(* *)
(***********************************************************************)
(* $Id$ *)
(function "quick" (lo: int hi: int a: addr)
(if (< lo hi)
(let (i lo
j hi
pivot (addraref a (>>s hi 1)))
(while (< i j)
(catch
(while 1
(if (>= i hi) exit [])
(if (> (addraref a (>>s i 1)) pivot) exit [])
(assign i (+ i 2)))
with [])
(catch
(while 1
(if (<= j lo) exit [])
(if (< (addraref a (>>s j 1)) pivot) exit [])
(assign j (- j 2)))
with [])
(if (< i j)
(let temp (addraref a (>>s i 1))
(addraset a (>>s i 1) (addraref a (>>s j 1)))
(addraset a (>>s j 1) temp))
[]))
(let temp (addraref a (>>s i 1))
(addraset a (>>s i 1) (addraref a (>>s hi 1)))
(addraset a (>>s hi 1) temp))
(app "quick" lo (- i 2) a unit)
(app "quick" (+ i 2) hi a unit))
[]))
(function "quicksort" (lo: int hi: int a: addr)
(app "quick" (+ (<< lo 1) 1) (+ (<< hi 1) 1) a unit))
![swh spinner](/static/img/swh-spinner.gif)
Computing file changes ...