1 / 15

CSCI 2720 Lists III

CSCI 2720 Lists III. Eileen Kraemer University of Georgia Spring 2007. DLL - Doubly Linked Lists. Nodes have two pointer fields Next Prev Next(Prev(P)) and Prev(Next(P)) -- would be nice if they always evaluated to P, but … Next(Prev(P)) -- breaks on first Prev(Next(P)) -- breaks on last.

janet
Download Presentation

CSCI 2720 Lists III

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSCI 2720Lists III Eileen Kraemer University of Georgia Spring 2007

  2. DLL - Doubly Linked Lists • Nodes have two pointer fields • Next • Prev • Next(Prev(P)) and Prev(Next(P)) -- would be nice if they always evaluated to P, but … • Next(Prev(P)) -- breaks on first • Prev(Next(P)) -- breaks on last Prev Next A C B

  3. DLL Header • Next(Prev(P)) and Prev(Next(P)) now OK Next Prev A B C

  4. DLLs • Forward traversal easy • Backward traversal easy • Insertion before item easy • Insertion after item easy

  5. DLLInsert Procedure DLLInsert(ptr P,Q): //Insert node pointed to by P just after node pointed to by Q

  6. DLLDelete • Procedure DLLDelete(ptr P): • //Delete cell P from its DLL

  7. DLLs vs. SLLs • Pro: • Can delete in O(1) knowing only address of node to be deleted • Easy backward traversal • Con • Requires 2x the memory for pointers

  8. XOR pointers • “trick” to compress composite of addresses in preceding and succeeding nodes into a single pointer-sized field • Saves memory • Requires more elaborate methods to traverse list (in either direction)

  9. What is XOR? • Bit-wise exclusive-or • When applied twice to same value, returns to original value • Works like a toggle switch

  10. XOR Example • Add1 = 4 (0100), • Add2 = 8 (1000) • Result = Add1  Add2 = 1100 • Result  Add1 = 1000 (original Add2) • Result  Add2 = 0100 (original Add1)

  11. XOR used in graphics • To do “rubber-banding” • Don’t have to remember previous value of pixel that you overwrite …. Just XOR same value on that location 2X and it returns to the original value

  12. Implementing DLL with XOR • Link(X) = • To traverse, need P and Q, pointers to two adjacent nodes

  13. Traversing with XOR • Forward(P,Q):

  14. Traversing with XOR • Backward(P,Q):

  15. Inserting a new node with XOR • To insert a new node pointed to by C between those pointed to by P and Q:

More Related