2 Replies - 783 Views - Last Post: 04 May 2011 - 08:22 AM Rate Topic: -----

#1 SteveA12  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 24-March 11

Doubly Linked Data Structure

Posted 02 May 2011 - 11:45 AM

Iam having trouble understanding this concept I was given An Item class and with this class I am to create a node class that holds the items information as well as pointers going to the next and to the previous node my item class looks like this
Public Class StudentItem
    Inherits Object
    Implements IComparable

    Private _name As String
    Private _age As Integer

    Public Overrides Function Equals(ByVal obj As Object) As Boolean
        ' Check for null values and compare run-time types.
        '     If obj Is Nothing Or Not Me.GetType() Is obj.GetType() Then
        'Return False
        '   End If
        Dim student As StudentItem = CType(obj, StudentItem)
        If student Is Nothing Then
            Return False
        Else
            Return (_name = student.Name) And (_age = student.Age)
        End If
    End Function


    Public Property Name() As String
        Get
            Return _name
        End Get
        Set(ByVal value As String)
            If value.Length = 0 Then
                Throw New Exception("Name must have a valid name string")
            Else
                _name = value
            End If
        End Set
    End Property

    Public Property Age() As Integer
        Get
            Return _age
        End Get
        Set(ByVal value As Integer)
            If value < 0 Then
                Throw New Exception("Name must have a positive age value")
            Else
                _age = value
            End If
        End Set
    End Property

    Public Sub New(Optional ByVal studentName As String = Nothing, _
                   Optional ByVal studentAge As Integer = 0)
        Name = studentName
        Age = studentAge
    End Sub

    Public Function CompareTo(ByVal obj As Object) As Integer Implements System.IComparable.CompareTo
        Dim student As StudentItem = CType(obj, StudentItem)
        If student Is Nothing Then
            Throw New Exception("StudentItem.CompareTo expects a valid object to compare to")
        End If
        Dim comparison As Integer = Name.CompareTo(student.Name)
        If 0 = comparison Then comparison = Age.CompareTo(student.Age)
        Return comparison
    End Function

    Public Overrides Function ToString() As String
        Return Name & " (" & Age.ToString() & ")"
    End Function

End Class


And my node class looks like this:
Public Class NodeLink(Of T)
    Public node As T
    Public NextLink As NodeLink(Of T)
    Public PrevLink As NodeLink(Of T)

    Public Sub New(ByVal StudentItem As T)
        node = StudentItem
        NextLink = Nothing
        PrevLink = Nothing
    End Sub

End Class


My question is if I'm grasping the concept? I used a previous homework that implimented a single linked list structure and I was thinking that by just adding another point to my single list I would be good any ideas?

Is This A Good Question/Topic? 0
  • +

Replies To: Doubly Linked Data Structure

#2 JackOfAllTrades  Icon User is online

  • Saucy!
  • member icon

Reputation: 5954
  • View blog
  • Posts: 23,218
  • Joined: 23-August 08

Re: Doubly Linked Data Structure

Posted 03 May 2011 - 02:49 AM

Moved to VB.NET. VB6 is NOT VB.NET.
Was This Post Helpful? 0
  • +
  • -

#3 SteveA12  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 24-March 11

Re: Doubly Linked Data Structure

Posted 04 May 2011 - 08:22 AM

I was moved From VB.NET
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1