- sub swap(byref a, byref b)
- t = a
- a = b
- b = t
- end sub
-
- sub sort(byref a(), l, r)
- elem = a(l + (r - l) \ 2)
- lb = l : rb = r
- do while lb <= rb
- do while a(lb) < elem : lb = lb + 1 : loop
- do while a(rb) > elem : rb = rb - 1 : loop
- if lb <= rb then
- swap a(lb), a(rb)
- lb = lb + 1
- rb = rb - 1
- end if
- loop
- if l < rb then sort a, l, rb
- if lb < r then sort a, lb, r
- end sub
-
-
- dim a(4) : a(1) = 2 : a(2) = 2 : a(3) = 5 : a(4) = 3
- dim b(4) : b(1) = 7 : b(2) = 2 : b(3) = 11 : b(4) = 13
- dim c()
- redim c(ubound(a) * ubound(b))
- for i = 1 to ubound(a)
- for j = 1 to ubound(b)
- c((i - 1) * ubound(b) + j) = a(i)^3 + b(j)^3
- next
- next
- dim d()
- redim d(ubound(c))
- for i = 1 to ubound(c)
- d(i) = c(i)
- next
- sort d, 1, ubound(d)
- msgbox join(a, " ") & vbcrlf & join(b, " ") & vbcrlf & join(c, " ") & vbcrlf & join(d, " ")
Ответить
|