LinkedListNote and 70-536 Exam

Posted on 2009-04-15
Last Modified: 2013-11-26
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.

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)


    End Sub

End Module

Open in new window

Question by:iammrkcohen
    LVL 8

    Accepted Solution

    In the example above vList.AddAfter returns the Node that was added (ie the 2nd parameter). So after line 21 executes, vNode equals v1.  It could be rewritten as follows:

    vList.AddFirst(v2)  'b
    vList.AddFirst(v5)  'e, b
    vList.AddLast(v3)  'e,b,c
    vList.AddAfter(v2, v1) 'e, b, a, c
    vList.AddBefore(v1, v4) 'e, b,  d, a c

    Let me know if that's still confusing

    LVL 69

    Assisted Solution

    by:Éric Moreau
    after this line:
    vNode = vList.AddAfter(vNode, v1)   ' e, b, a, c - makes sense

    vNode contains a reference to "a" which is the element that was just inserted

    The following line will insert "d" BEFORE vNode wchich is in fact a reference to "a"

    vNode = vList.AddBefore(vNode, v4)  ' ??????????? - not a clue

    Author Comment

    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?


    vNode = vList.AddAfter(vNode, v1) ---> vNode would become v1 here?
    vNode = vList.AddBefore(vNode, v3) ---> vNode would become v3 here?
    LVL 69

    Assisted Solution

    by:Éric Moreau
    exactly. in fact, it retains a reference to the last node you have inserted.

    Author Comment

    Thanks so much. I've solved several of these correctly now. Now on to the other 10,000 topics for this exam.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now