Posted by: Sourav | September 23, 2016

Generic Stack Collection Class,Visual Basic teacher Sourav,Kolkata 09748184075


Module Module1

Sub Main()

Dim customer1 As New Customer() With { _
.ID = 101, _
.Name = “Mark”, _
.Gender = “Male” _
}

Dim customer2 As New Customer() With { _
.ID = 102, _
.Name = “Pam”, _
.Gender = “Female” _
}

Dim customer3 As New Customer() With { _
.ID = 103, _
.Name = “John”, _
.Gender = “Male” _
}

Dim customer4 As New Customer() With { _
.ID = 104, _
.Name = “Ken”, _
.Gender = “Male” _
}

Dim customer5 As New Customer() With { _
.ID = 105, _
.Name = “Valarie”, _
.Gender = “Female” _
}
‘Dim queuecustomers As Queue(Of Customer) = New Queue(Of Customer)
‘queuecustomers.Enqueue(customer1)
‘queuecustomers.Enqueue(customer2)
‘queuecustomers.Enqueue(customer3)
‘queuecustomers.Enqueue(customer4)
‘queuecustomers.Enqueue(customer5)

‘Dim c1 As Customer = queuecustomers.Dequeue
‘Console.WriteLine(c1.ID & “.” & c1.Name)
‘Console.WriteLine(“Total items in the queue is {0}”, queuecustomers.Count)
‘Dim c2 As Customer = queuecustomers.Dequeue
‘Console.WriteLine(c2.ID & “.” & c2.Name)
‘Console.WriteLine(“Total items in the queue is {0}”, queuecustomers.Count)
‘Dim c3 As Customer = queuecustomers.Dequeue
‘Console.WriteLine(c3.ID & “.” & c3.Name)
‘Console.WriteLine(“Total items in the queue is {0}”, queuecustomers.Count)
‘Dim c4 As Customer = queuecustomers.Dequeue
‘Console.WriteLine(c4.ID & “.” & c4.Name)
‘Console.WriteLine(“Total items in the queue is {0}”, queuecustomers.Count)
‘Dim c5 As Customer = queuecustomers.Dequeue
‘Console.WriteLine(c5.ID & “.” & c5.Name)
‘Console.WriteLine(“Total items in the queue is {0}”, queuecustomers.Count)
‘queuecustomers.Enqueue(customer1)
‘queuecustomers.Enqueue(customer2)
‘queuecustomers.Enqueue(customer3)
‘queuecustomers.Enqueue(customer4)
‘queuecustomers.Enqueue(customer5)
‘Console.WriteLine(“iterate through queue”)

‘For Each c As Customer In queuecustomers
‘    Console.WriteLine(c.ID & “.” & c.Name)
‘    ‘ Console.WriteLine(“Total items in the queue is {0}”, queuecustomers.Count)
‘Next
‘Dim cpeek As Customer = queuecustomers.Peek
‘Console.WriteLine(cpeek.ID & “.” & cpeek.Name)
” Console.WriteLine(“Total items in the queue is {0}”, queuecustomers.Count)

‘If queuecustomers.Contains(customer1) Then
‘    Console.WriteLine(“customer1 exists”)
‘Else
‘    Console.WriteLine(“customer1 does not exist”)
‘End If

Dim stackcustomers As Stack(Of Customer) = New Stack(Of Customer)
stackcustomers.Push(customer1)
stackcustomers.Push(customer2)
stackcustomers.Push(customer3)
stackcustomers.Push(customer4)
stackcustomers.Push(customer5)

Dim c1 As Customer = stackcustomers.Pop
Console.WriteLine(c1.ID & “.” & c1.Name)
Console.WriteLine(“Total items in the stack is {0}”, stackcustomers.Count)
Dim c2 As Customer = stackcustomers.Pop
Console.WriteLine(c2.ID & “.” & c2.Name)
Console.WriteLine(“Total items in the stack is {0}”, stackcustomers.Count)
Dim c3 As Customer = stackcustomers.Pop
Console.WriteLine(c3.ID & “.” & c3.Name)
Console.WriteLine(“Total items in the stack is {0}”, stackcustomers.Count)
Dim c4 As Customer = stackcustomers.Pop
Console.WriteLine(c4.ID & “.” & c4.Name)
Console.WriteLine(“Total items in the stack is {0}”, stackcustomers.Count)
Dim c5 As Customer = stackcustomers.Pop
Console.WriteLine(c5.ID & “.” & c5.Name)
Console.WriteLine(“Total items in the stack is {0}”, stackcustomers.Count)
Console.WriteLine(“iterate through stack”)
stackcustomers.Push(customer1)
stackcustomers.Push(customer2)
stackcustomers.Push(customer3)
stackcustomers.Push(customer4)
stackcustomers.Push(customer5)

For Each c As Customer In stackcustomers
Console.WriteLine(c.ID & “.” & c.Name)
Console.WriteLine(“Total items in the queue is {0}”, stackcustomers.Count)
Next

Dim cpeek As Customer = stackcustomers.Peek
Console.WriteLine(cpeek.ID & “.” & cpeek.Name)
Console.WriteLine(“Total items in the queue is {0}”, stackcustomers.Count)

If stackcustomers.Contains(customer1) Then
Console.WriteLine(“customer1 exists”)
Else
Console.WriteLine(“customer1 does not exist”)
End If

Console.ReadLine()

End Sub

End Module

Public Class Customer
Public Property ID() As Integer
Get
Return m_ID
End Get
Set(ByVal value As Integer)
m_ID = Value
End Set
End Property
Private m_ID As Integer
Public Property Name() As String
Get
Return m_Name
End Get
Set(ByVal value As String)
m_Name = Value
End Set
End Property
Private m_Name As String
Public Property Gender() As String
Get
Return m_Gender
End Get
Set(ByVal value As String)
m_Gender = Value
End Set
End Property
Private m_Gender As String
End Class

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: