代码(待更新):

class Vector
Private length
Private data()
Sub Class_Initialize()
length=
End Sub
'插入元素'
public Function Add (byval x)
length=length+
redim preserve data(length-)
data(length-)=x
End Function
'快速展示'
public Function display()
dim i
dim s
for i= to length-
s=s & cstr(data(i)) & " "
next
msgbox s
End Function
'返回大小'
public Function size()
size= length
End Function
'获取元素'
public Function getAt (byval pos)
if pos< or pos>length- then
getAt=
exit Function
end if
getAt=data(pos)
End Function
'删除元素'
public Function delAt (byval pos)
if pos< or pos>length- then exit Function '注意退出函数的表达式'
dim i
for i=pos to length-
data(i)=data(i+)
next
length=length-
End Function
'插入元素'
public Function insert (byval pos,byval elem)
if pos< or pos>length- then exit Function
dim i
length=length+
redim preserve data(length-)
for i=length- to pos+ step -
data(i)=data(i-)
next
data(pos)=elem
End Function
end class

调用:

set v = new Vector
v.Add
v.Add
v.Add
v.display
v.delAt
v.insert ,
v.display

完整代码:

class Vector
Private length
public data()
Sub Class_Initialize()
length=
End Sub
'插入元素'
public Function Add (byval x)
length=length+
redim preserve data(length-1)
data(length-1)=x
End Function
'快速展示'
public Function display()
dim i
dim s
for i= to length-1
s=s & cstr(data(i)) & " "
next
msgbox s
End Function
'返回大小'
public Function size()
size= length
End Function
'获取元素'
public Function getAt (byval pos)
if pos<0 or pos>length-1 then
getAt=
exit Function
end if
getAt=data(pos)
End Function
'删除元素'
public Function delAt (byval pos)
if pos<0 or pos>length-1 then '注意退出函数的表达式'
dim i
for i=pos to length-2
data(i)=data(i+)
next
length=length-1
redim preserve data(length-1)
End Function
'插入元素'
public Function insert (byval pos,byval elem)
if pos<0 or pos>length-1 then exit Function
dim i
length=length+
redim preserve data(length-1)
for i=length-1 to pos+ step -
data(i)=data(i-1)
next
data(pos)=elem
End Function
end class public Function extendProcess (byval exe,byval arr) '程序名、数组'
dim i
dim cmd
cmd=exe
For i= To ubound(arr)
cmd=cmd & " " & arr(i)
Next
dim objShell '执行命令'
Set objShell = CreateObject("Wscript.Shell")
objShell.Run(cmd)
'读入输出文件val.txt'
Set fs = CreateObject("Scripting.FileSystemObject")
Set file = fs.OpenTextFile("val.txt", , false)
info=file.readall
file.close
set fs=nothing
'处理信息'
extendProcess=split(info) '用空格分隔'
End Function set v = new Vector
v.Add
v.Add
v.Add
v.Add
v.Add
v.Add
v.Add
v.Add
ans=extendProcess("mysort",v.data) '如果函数有返回,就必须要有括号。如果无返回,并且参数数目大于1,不能带括号'
set v2 = new Vector
for each x in ans
v2.Add x
next
v2.display ' dim objShell
' Set objShell = CreateObject("Wscript.Shell")
' objShell.Run("%comspec% /k ipconfig /all")

vbs实现c++的vector的更多相关文章

  1. vbs与其他语言进行交互编程(外存传参)

    vbs没有自定义排序函数.无需自己造轮子,可以用其他语言来完成这个任务(在传递数据比较简单的情况下,例如只传递数组). 首先用5分钟写一个C++排序的代码.命名为“mysort.cpp”: #incl ...

  2. c++ vector 使用

    1. 包含一个头文件: 1 #include <vector> 2. 申明及初始化: std::vector<int> first; // empty vector of in ...

  3. Vector Tile

    Mapbox Vector Tile Specification A specification for encoding tiled vector data. <?XML:NAMESPACE ...

  4. ArrayList、Vector、LinkedList的区别联系?

    1.ArrayList.Vector.LinkedList类都是java.util包中,均为可伸缩数组. 2.ArrayList和Vector底层都是数组实现的,所以,索引数据快,删除.插入数据慢. ...

  5. ArrayList、Vector、HashMap、HashSet的默认初始容量、加载因子、扩容增量

    当底层实现涉及到扩容时,容器或重新分配一段更大的连续内存(如果是离散分配则不需要重新分配,离散分配都是插入新元素时动态分配内存),要将容器原来的数据全部复制到新的内存上,这无疑使效率大大降低. 加载因 ...

  6. Java中Vector和ArrayList的区别

    首先看这两类都实现List接口,而List接口一共有三个实现类,分别是ArrayList.Vector和LinkedList.List用于存放多个元素,能够维护元素的次序,并且允许元素的重复.3个具体 ...

  7. C++使用vector

    #include <iostream> #include <string> #include <vector> using namespace std; void ...

  8. [LeetCode] Flatten 2D Vector 压平二维向量

    Implement an iterator to flatten a 2d vector. For example,Given 2d vector = [ [1,2], [3], [4,5,6] ] ...

  9. C#调用vbs脚本实现Windows版Siri

    最近新加入,把自己一些有意思的小东西分享给大家,我是一个学生,代码写得少,哪里不规范,希望大家见谅. 这事我封装好的一个类,可以直接实例化对象之后,调用"对象.Talk()"方法, ...

随机推荐

  1. LG1840 Color the Axis 线段树

    菜的人就要写简单题 为了练习手速来写这样一道 珂朵莉树 线段树简单题 没啥可说的,注意修改操作中要判一下 val=0 #include<bits/stdc++.h> using names ...

  2. Fiddler修改请求数据

    截断方法一: 在菜单中选择“Rules”->“Automatic Breakpoint”->“Before Requests”,这种方式会截断所有Request请求. 2.浏览器打开站点, ...

  3. GNSS频率分配表

    说明: 公开资料表示,GPS L3用于核爆炸等高能红外辐射事件的侦查,L4用于电离层研究. GLONASS FDMA信号G1.G2.G3三个频段各自频点见以下附表,摘自ITU的频率协调结果. GLON ...

  4. PI对于两个SAP客户端通道的了解

    你把你的报文放到ESR的MM里面试一下就知道了 日期格式之类的,可能有转换的你要输入2019-05-13这种 OA到PI不选,都是到一个系统,由PI再来分流 如果你要做成由OA来选的,就要参考类似于  ...

  5. 练手WPF(三)——扫雷小游戏的简易实现(上)

    一.创建项目1.创建WPF项目,设置初始化窗口大小(初级难度):高x宽为430x350.2.添加文件夹Images,并添加相关图片. 3.xaml中引入图片资源. <Window.Resourc ...

  6. SpringBoot(十):SpringBoot整合Memcached

    一.环境准备memcached 1.4.5SpringBoot 1.5.10.RELEASEjava_memcached-release_2.6.6.jarmemcached 1.4.5 window ...

  7. SpringBoot(七) SpringBoot整合Log4j

    第一种打印debug日志方式: logging.level.com.demo.mapper: debug 第二种打印debug日志方式: 在resource文件夹下新建:logback.xml < ...

  8. Docker关于镜像、容器的基本命令

    镜像 1.获取镜像 docker pull 服务器:端口/仓库名称:镜像 ➜ ~ docker pull python Using default tag: latest 2.查看镜像信息 列出本机所 ...

  9. ES6复制拷贝数组,对象,json数组

    扩展运算符的应用spread打散数组[...] (1)复制数组 数组是复合的数据类型,直接复制的话,只是复制了指向底层数据结构的指针,而不是克隆一个全新的数组. const a1 = [1, 2]; ...

  10. Meterpreter初探

    Meterpreter Meterpreter号称"黑客瑞士军刀",Meterpreter是Metasploit框架中的一个杀手锏,通常作为漏洞溢出后的攻击载荷使用,攻击载荷在触发 ...