Link to home
Start Free TrialLog in
Avatar of iammrkcohen
iammrkcohen

asked on

LinkedListNote and 70-536 Exam

Can anyone help to explain to me how the heck this little program returns "E, B, D, A, C"?

My real problem is that I'm not getting how the LinkedListNode thing works. I understand LinkedList.AddFirst and LinkedList.AddLast...etc. But when it comes to the LinkedListNode = LinkList.AddBefore(LinkedListNode, item) I get really lost. How does this work?

The MSDN explanation sort of confuses me more.
http://msdn.microsoft.com/en-us/library/ahf4c754.aspx


Module Module1
    Sub Main()
 
        Dim v1 As String
        Dim v2 As String
        Dim v3 As String
        Dim v4 As String
        Dim v5 As String
 
        v1 = "A"
        v2 = "B"
        v3 = "C"
        v4 = "D"
        v5 = "E"
 
        Dim vList As New LinkedList(Of String)
        Dim vNode As LinkedListNode(Of String)
        vNode = vList.AddFirst(v2)          ' b - makes sense
        vList.AddFirst(v5)                  ' e, b - makes sense
        vList.AddLast(v3)                   ' e, b, c - makes sense
        vNode = vList.AddAfter(vNode, v1)   ' e, b, a, c - makes sense
        vNode = vList.AddBefore(vNode, v4)  ' ??????????? - not a clue
 
        For Each v As String In vList
            Console.WriteLine("{0}", v)
        Next
 
    End Sub
End Module

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ppittle
ppittle
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of iammrkcohen
iammrkcohen

ASKER

So is it fair to say that every time I make an assignment to vNode, it retains the value of the last individual item appended to it?

so:

vNode = vList.AddAfter(vNode, v1) ---> vNode would become v1 here?
vNode = vList.AddBefore(vNode, v3) ---> vNode would become v3 here?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks so much. I've solved several of these correctly now. Now on to the other 10,000 topics for this exam.

Thanks,
Mike