vb.net中创建类
使用VB.net编写这个Stack类!定义一个Stack类用来建立可存放整数的堆栈对象.类成员如下:(1)aryData()数组:该数组用来存放堆栈内的元素(2)SubN...
使用VB.net编写这个Stack类!
定义一个Stack类用来建立可存放整数的堆栈对象.类成员如下:
(1)aryData()数组:该数组用来存放堆栈内的元素
(2)Sub New(ByVal Num as Integer)构造函数:用来建立可存放Num个元素的aryData()整形数组.
(3)Function Pop() as Integer :用来取出aryData数组堆栈的一个元素,若无元素则返回0.
(4)Sub Push(ByVal n as Integer):可将n值放入到aryData数组堆栈中,若堆栈已满则显示"堆栈已满"的消息.
(5)Sub PrintStack():输出堆栈内所有的元素. 展开
定义一个Stack类用来建立可存放整数的堆栈对象.类成员如下:
(1)aryData()数组:该数组用来存放堆栈内的元素
(2)Sub New(ByVal Num as Integer)构造函数:用来建立可存放Num个元素的aryData()整形数组.
(3)Function Pop() as Integer :用来取出aryData数组堆栈的一个元素,若无元素则返回0.
(4)Sub Push(ByVal n as Integer):可将n值放入到aryData数组堆栈中,若堆栈已满则显示"堆栈已满"的消息.
(5)Sub PrintStack():输出堆栈内所有的元素. 展开
2013-08-15
展开全部
不熟悉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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询