Presentation is loading. Please wait.

Presentation is loading. Please wait.

Single Pointer Implemention

Similar presentations


Presentation on theme: "Single Pointer Implemention"— Presentation transcript:

1 Single Pointer Implemention
Lists ADT Array Implementation Single Pointer Implemention Cursors Doubly Linked Ring 9/21/2018 CS 303 –Lists Lecture 4

2 ADT List - Operations L = MakeNull() Insert(L,p,x) Delete(L,p)
p = First(L) p = End(L) p = Previous(L,p) p = Next(L,p) p = Locate(L,x) x = Retrieve(L,p) x: ElementType p: PositionType L: ListType Why isn’t First(L)always 1? Because Position is hidden! No arithmetic is allowed (by the user) on Positions. Use Previous and Next! 9/21/2018 CS 303 –Lists Lecture 4

3 Array Implementation a1 a2 1 2 n an MaxLength Last
Internal routines can do arithmetic on “positions”, but external (user) routines cannot. Why? 9/21/2018 CS 303 –Lists Lecture 4

4 Single Pointer Implementation
??? a1 a2 ... an Header What is the purpose of the header? (Hing: consider “position”) Compare details (efficiency, behavior of “position”) with Array Implementation Array Pointer Previous/End EASY HARD Insert/Delete HARD EASY 9/21/2018 CS 303 –Lists Lecture 4

5 Cursors (an aside) Suppose you want to use pointers – but your programming environment does not support them? Use “cursors” Allocate an Array called CursorSpace Use indices into CursorSpace just like pointers Do your own memory management of cells New Dispose 9/21/2018 CS 303 –Lists Lecture 4

6 Doubly Linked Lists/Rings
? a? an Many variations Is ‘?’ a0 (Header) or a1? [a1] Is ‘L’ part of the structure, or an external pointer? [external] Is there a “First” element? [where L points!] Implement the full Ring! Everything is EASY; Position is natural 9/21/2018 CS 303 –Lists Lecture 4


Download ppt "Single Pointer Implemention"

Similar presentations


Ads by Google