[原创]擂台法数组把数组颠倒
例如,有a有10个元素,将a1=a10 a10=a1 a9=a2 a2=a9...代码在此
程序代码:
dim a(10) '声明 for i = 1 to 10 '赋值 a(i)=i next i ‘--------------------------------------split line for i=1 to Ubound(a)/2 '从1开始的数组 偶数 tmp=a(i) a(i)=a(Ubound(a)+1-i) a(Ubound(a)+1-i)=tmp next i for i=1 to (Ubound(a)-1)/2 '从1开始的数组 奇数 tmp=a(i) a(i)=a(Ubound(a)+1-i) a(Ubound(a)+1-i)=tmp next i for i=0 to Ubound(a)/2-1 '从0开始的数组 偶数 tmp=a(i) a(i)=a(Ubound(a)-i-1) a(Ubound(a)-i-1)=tmp next i for i=0 to (Ubound(a)-1)/2-1 '从0开始的数组 奇数 -1为了中间的数不替换 tmp=a(i)z a(i)=a(Ubound(a)-i-1) a(Ubound(a)-i-1)=tmp next i