+ -
当前位置:首页 → 问答吧 → 向数组中插入元素求详解

向数组中插入元素求详解

时间:2011-12-18

来源:互联网

学习vb过程中 向数组插入元素有点弄不明白
原理是先排序现在的数组,然后插入新元素对比大小排序
源码中先定义数组下标10
然后是俩个for循环来对比大小
for 1 to 8
  for 1 to 9
完整源码现在想不起来了,就是在这个地方有点想不明白
元素是11个,为什么循环对比时是1to8 1 to 9
求完整源码带详细解释

作者: csKongKong   发布时间: 2011-12-18

这个是什么代码?

最原始的排序数组

sub SortArr(a() as long)
dim mIdx as long
dim i as long
dim j as long
dim mMin as long
mIdx=ubound(a)
for i=0 to mIdx
for j=i+1 to mIdx
if a(i)>a(j) then
mMin=a(j)
a(j)=a(i)
a(i)=aMin
end if
next
next
end sub

作者: worldy   发布时间: 2011-12-18