如何在数组中插入一个数并按原来从大到小的顺序排列
答案:3 悬赏:80 手机版
解决时间 2021-03-19 09:15
- 提问者网友:十年饮冰
- 2021-03-18 15:09
如何在数组中插入一个数并按原来从大到小的顺序排列
最佳答案
- 五星知识达人网友:三千妖杀
- 2021-03-18 15:19
要看嘛语言了,不过道理都一样,有个偷懒的办法,你把这个数就放数组尾部,然后全数组一排序就可以了
全部回答
- 1楼网友:春色三分
- 2021-03-18 16:46
private sub command1_click() dim s1() as integer, i as integer, s2 as string dim t1 as integer, t2 as integer redim s1(10) for i = 0 to 10 s1(i) = i next s2 = inputbox("请输入数值和位置,格式:值|位置", "", "31|2") if s2 <> "" then t1 = mid(s2, 1, instr(1, s2, "|") - 1) t2 = mid(s2, instr(1, s2, "|") + 1, 10) if t2 <= ubound(s1) then redim preserve s1(ubound(s1) + 1) for i = ubound(s1) to t2 step -1 s1(i) = s1(i - 1) next s1(t2) = t1 else redim preserve s1(ubound(s1) + 1) s1(ubound(s1)) = t1 end if end if for i = 0 to ubound(s1) print s1(i) next end sub
- 2楼网友:持酒劝斜阳
- 2021-03-18 15:39
是啊,要重新声明一个数组,长度+1,
如果原来有序,那就循环一下,找到合适的位置插入元素,continue一次
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯