Doubly Linked Lists - PowerPoint PPT Presentation

About This Presentation
Title:

Doubly Linked Lists

Description:

rover- prev- next=rover- next; rover- next- prev=rover- prev; Inserting to a DLL ... rover; newNode- prev=rover- prev; rover- prev- next=newNode; rover- prev ... – PowerPoint PPT presentation

Number of Views:53
Avg rating:3.0/5.0
Slides: 8
Provided by: markc49
Category:
Tags: doubly | linked | lists | rover

less

Transcript and Presenter's Notes

Title: Doubly Linked Lists


1
Doubly Linked Lists
  • 11-16-2001

2
Opening Discussion
  • What did we talk about last class?
  • Who would like to draw the way that a linked list
    based stack does push and pop? How about a
    queue?
  • When I say doubly linked list, what do you think
    that I mean?
  • We are down to 7 regular class days left for this
    class.

3
Doubly Linked Lists
  • We have talked about lists where you keep a
    single pointer to the next element. It is easy
    to imagine extending this to include a pointer to
    the previous element as well.
  • A list with links both forward and backward is
    called a doubly linked listed for obvious reasons.

4
Deleting from a DLL
  • Because a node in a doubly linked list knows
    about both the next element and the previous one,
    you can do a delete when you only have one node.
    It has to do two links instead of one though.

rover-gtprev-gtnextrover-gtnext rover-gtnext-gtprevr
over-gtprev
5
Inserting to a DLL
  • Same thing that was true for deleting is also
    true for inserting.
  • Always link the new nodes to the old nodes first
    so you dont overwrite links.

newNode-gtnextrover newNode-gtprevrover-gtprev ro
ver-gtprev-gtnextnewNode rover-gtprevnewNode
6
Code
  • Lets look at how we would change our linked list
    code so that it creates and uses doubly linked
    lists instead of singly linked ones.
  • What are the drawbacks of the doubly linked list?
    What are the advantages? Do you think the
    advantages are worth it?

7
Minute Essay
  • We have now completed our coverage of linked
    lists and recursive data types. However, they
    will be reappearing in later discussions, just as
    loops, arrays, etc. have continually reappeared.
    Do you have any questions about them?
  • Next class we start talking about inheritance.
    You should read 10.1 and 10.2 for that.
Write a Comment
User Comments (0)
About PowerShow.com