Algorithm: sort(a, b, c, d)
if a > b then swap(a, b)
if c > d then swap(c, d)
if a > c then swap(a, c)
if b > d then swap(b, d)
if b > c then swap(b, c)
subroutine: swap(x, y)
temp <- x
x <- y
y <- temp
The resulting sequence a, b, c, d will be sorted in ascending order.
Showing posts with label 4 numbers. Show all posts
Showing posts with label 4 numbers. Show all posts
Tuesday, August 9, 2011
Subscribe to:
Posts (Atom)