Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "CSCI 2720 Lists III Eileen Kraemer University of Georgia Spring 2007."— Presentation transcript:

1 CSCI 2720 Lists 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 A Prev Next C B

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

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:


Download ppt "CSCI 2720 Lists III Eileen Kraemer University of Georgia Spring 2007."

Similar presentations


Ads by Google