职业考试 | 在线试题 | 作文辅导 | 范文大全 | 中小学教育 | 试题教案课件

当前位置:得高分网试题在线计算机等级考试计算机二级考试计算机等级考试二级VB常用算法(7):排序

计算机二级考试

当前:首页 >> 计算机等级考试二级VB常用算法(7):排序

计算机等级考试二级VB常用算法(7):排序

日期:09-27 13:38:45 | 计算机二级考试 | 浏览次数: 801 次 | 收藏

标签:计算机二级考试真题,国家计算机二级考试,计算机二级考试试题,http://www.gaofen123.com 计算机等级考试二级VB常用算法(7):排序,

1、算法说明数组中元素的插入和删除一般是在已固定序列的数组中插入或删除一个元素,使得插入或删除操作后的数组还是有序的。
基本思路:首先要找到插入位置或要删除的元素。
1) 插入

代码如下:
private submand1_click()
dim a(10) as integer
dim i as integer, k as integer
for i = 0 to 9 '生成数组
a(i) = i * 3 + 1
print a(i);
next i
print
print "插入14"
for k = 0 to 9 '查找插入14在数组中的位置
if 14 < a(k) then exit for
next k
for i = 9 to k step -1 '从最后元素开始逐个后移,腾出位置
a(i + 1) = a(i)
next i
a(k) = 14 '插入数14
for i = 0 to 10
print a(i);
next i
print
end sub
2) 1 4 7 10 13 16 19 22 25 28

k删除 代码如下:
dim a() as integer
….
redim a(1 to n)

for i=k+1 to n
a(i-1)=a(i)
next i
redim preserve a(1 to n-1)


[1] [2]  下一页

相关分类

计算机二级考试 更新

计算机二级考试 热门排行