重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
递归可以用迭代来等价代替。
成都创新互联公司服务项目包括潼南网站建设、潼南网站制作、潼南网页制作以及潼南网络营销策划等。多年来,我们专注于互联网行业,利用自身积累的技术优势、行业经验、深度合作伙伴关系等,向广大中小型企业、政府机构等提供互联网行业的解决方案,潼南网站推广取得了明显的社会效益与经济效益。目前,我们服务的客户以成都为中心已经辐射到潼南省份的部分城市,未来相信会继续扩大服务区域并继续获得客户的支持与信任!
Option Explicit
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Const QueueVolume = 1000000
Private QueueX(QueueVolume) As Long
Private QueueY(QueueVolume) As Long
Private SrcColor As Long, DestColor As Long
Private QStart As Long, QEnd As Long
Private Function EnQueue(ByVal X As Long, ByVal Y As Long) As Boolean
If (QEnd + 1) Mod QueueVolume QStart Then
QueueX(QEnd) = X
QueueY(QEnd) = Y
QEnd = QEnd + 1
EnQueue = True
Else
EnQueue = False
End If
End Function
Private Function DeQueue(ByRef X As Long, ByRef Y As Long) As Boolean
If QStart QEnd Then
X = QueueX(QStart)
Y = QueueY(QStart)
QStart = QStart + 1
DeQueue = True
Else
DeQueue = False
End If
End Function
Private Sub Qytc()
Dim X As Long, Y As Long
Dim cr As Long
Do While DeQueue(X, Y)
cr = GetPixel(Picture1.hdc, X, Y)
If cr = SrcColor Then
Picture1.PSet (X, Y), DestColor
EnQueue X, Y - 1
EnQueue X, Y + 1
EnQueue X - 1, Y
EnQueue X + 1, Y
End If
DoEvents
Loop
End Sub
Private Sub Command1_Click()
EnQueue 5, 6
Qytc
End Sub
Private Sub Form_Load()
QStart = 0 '队列左端
QEnd = 0 '队列右端
SrcColor = RGB(255, 0, 0)
DestColor = RGB(0, 0, 255)
End Sub
说明:放一个PictureBox1,ScaleMode设为3-pixel,BackColor改成红色。
放一个按扭Command1。
如果队列长度不够,把Private Const QueueVolume = 1000000 再改大点。
只适用于VB6。
(用VB.net就不用这么麻烦了)
Imports System.Runtime.InteropServices
Module APIs
StructLayout(LayoutKind.Sequential)
Public Structure FILETIME
Public dwLowDateTime As UInteger
Public dwHighDateTime As UInteger
Public ReadOnly Property Value() As ULong
Get
Return CType(dwHighDateTime 32, ULong) + dwLowDateTime
End Get
End Property
End Structure
Public Delegate Sub TimerCompleteDelegate()
DllImport("kernel32.dll")
Public Function CreateWaitableTimer(lpTimerAttributes As IntPtr, bManualReset As Boolean, lpTimerName As String) As IntPtr
End Function
DllImport("kernel32.dll")
Public Function SetWaitableTimer(hTimer As IntPtr, ByRef ft As Long, lPeriod As Int32, pfnCompletionRoutine As TimerCompleteDelegate, pArgToCompletionRoutine As IntPtr, fResume As Boolean) As Boolean
End Function
Public Function SetWaitableTimer(hTimer As IntPtr, ByRef ft As Long, lPeriod As Int32) As Boolean
Return SetWaitableTimer(hTimer, ft, lPeriod, Nothing, IntPtr.Zero, True)
End Function
End Module
SetWaitableTimer的声明错了
不熟悉VB,如有不妥的地方请包涵!
Public Class Stack
Dim aryData() As Integer
Sub New(ByVal Num As Integer)
Dim aryData(Num) As Integer
End Sub
Function Pop() As Integer
If (aryData.Length = 0) Then
Return 0
Else
Dim a As Integer
a = aryData(aryData.Length)
aryData(aryData.Length) = Convert.ToInt32(DBNull.Value)
Return a
End If
End Function
Sub Push(ByVal n As Integer)
For Each i As Integer In aryData
If (aryData(i) = Convert.ToInt32(DBNull.Value)) Then
aryData(i) = n
End
Else
Continue For
End If
Next
End Sub
Sub PrintStack()
For Each i As Integer In aryData
If (aryData(i) = Convert.ToInt32(DBNull.Value)) Then
End
Else
Print(aryData(i))
End If
Next
End Sub
End Class
默认堆栈大小1 MB
具体的我也不了解,在MSDN上找了到了点东西看看对你有没帮助:
建立新线程指定并线程的最大堆栈大小:
用EDITBIN的/STACK选项:
不行还是在C++那里想办法吧,比如减少堆栈的使用,少用递归之类的。
水平不够就说这些了。
题主用的是 VB6 时代的 Windows API,那里面的 Long 类型相当于 .NET 里的 Int32,声明 API 时要把所有 Long 类型替换成 Int32 才可以正常使用,否则堆栈溢出。
另外操作内存这种函数需要管理员权限来运行,否则程序会报错甚至崩溃。
1、声明数组的语句:
Dim types( ) As integer
2、然后使用ReDim语句来配置数组大小。
ReDim Types(X+1)
3、假设想改变数组大小又不想丢失原来的数据,仅仅要在ReDim语句中包括Preservekeyword就能够,典型语句为:
ReDa_m PresetVe Types(10,23)
对于多维数组,在使用Preservekeyword时,仅仅能改动最后一维的大小。假设改变其它维,那么将出现执行错误。假设不清楚某维的当前大小,能够使用GetI~ength函数来获取。
扩展资料:
数组的使用:
用For Each来循环遍历一个数组。比如:
Dim x As Integer
F0r Each x In arrayl
Console.WriteLine(x)
Next
在使用数组时还要注意,不仅声明语法有变化,并且在执行时处理方式也有了非常大的变化。VB.NET在堆栈中给数组分配地址空间,当向一个方法传递数组类型的参数时,使用的是引用传递而不是值传递。以下是互相传递数组引用的三个方法:
Dim arrayl(3,3)AS Integer
Dim array2 As Integer(,)
Redim array2(3,3)
Dim array3 As Integer(,)={{2,4},{12,29}}