#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    31
    Rep Power
    3

    Doubly Linked Lists


    Hello!

    So on my homework, I'm given an initial Doubly linked list with 3 objects: in the first object is 12, the second object is 26, and the third is 46.

    First is pointing to 12 & Last is pointing to 46.

    Given the certain operations
    Code:
    deleteLast(), deleteLast(), insertFirst(26), deleteFirst(), insertLast(72), insertLast(65)
    I have to draw the new list.

    What I'm having trouble understanding is how the "previous" part of this linked list works (or if it plays any role in the operations given to me). I'm new to this and so I need some explanation on Doubly Linked Lists. So could anyone please explain it to me? I'm still new to Java.
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,724
    Rep Power
    348
    A good way to see how linked lists work, is to use a paper and pencil to draw the nodes in the list and then connect the nodes with the next and previous links.

    If the list is:
    1
    2
    3
    looking at 2, next is 3 and previous is 1

IMN logo majestic logo threadwatch logo seochat tools logo