vb,在一个有序数组a(1 to n)中,删除一个元素,输出删除前后的数组

如题所述

你说得不太严谨,我先举个例子,你自己看看是不是你要的
已知要删除 a(1 to n)中的第i个元素,其中n,i的值要知道,代码如下:

print "删除前:" '输出删除前的数组
for j=1 to n
print a(j)
next j
print "删除后:" '输出删除后的数组
for q=1 to n-1
if q>=i then '用“压缩”的方法,将目标元素“压”掉
a(q)=a(q+1)
end if
print a(q)
next q
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-05-28
sub shanchu()
dim a(1 to n)
dim b()
dim c(1 to n)
dim i%, k%,l%,p%
p=0
'给数组a赋值
for i=1 to n
a(i)=.....
c(i)=a(i)
next
for k=1 to n
if a(k)= "标记" then
for j=k+1 to n-1
a(j-1)=a(j)
next j
p=p+1
end if
next k
redim b(1 to n-p)
for l=1 to n-p
b(l)=a(l)
print b(l) & chr(10)
next l
for i=1 to n
print c(i) & chr(10)
next i
end sub本回答被提问者采纳