Presentation is loading. Please wait.

Presentation is loading. Please wait.

Question of the Day  Two English words change their pronunciation when their first letter is capitalized. What are they?

Similar presentations


Presentation on theme: "Question of the Day  Two English words change their pronunciation when their first letter is capitalized. What are they?"— Presentation transcript:

1 Question of the Day  Two English words change their pronunciation when their first letter is capitalized. What are they?

2 Question of the Day  Two English words change their pronunciation when their first letter is capitalized. What are they?  Polish/polish Reading/reading

3 CSC 212 – Data Structures

4 Stack Memory Aid Roses are red and violets are blue Implement push, pop, & top And you’re a Stack too!

5 Stack Interface public interface Stack extends Collection { public E top() throws EmptyStackException; public E pop() throws EmptyStackException; public void push(E element); }

6 Queue Memory Aid

7 It’s hard writing rhymes with enqueue, dequeue, and front

8 Queue Memory Aid

9 public interface Queue extends Collection { public E dequeue() throws EmptyQueueException; public E front() throws EmptyQueueException; public void enqueue(E element); } Queue ADT

10 Stacks vs. Queues

11 Order read if Queue

12 Stacks vs. Queues Order read if Queue Order read if Stack

13  Cannot access both sides of either Collection  Transplant waiting lists  Help center phone banks  My Grandpa dealing cards for money  Stack only works with one end  Add & remove from top of the Stack  Queue limits how each side used  Front provides access & removal of elements  Must use the Queue ’s end to add elements Still Have Limits

14  Pronounced “deck” (like on a house) DEQUE  Mnemonic for Double Ended QUEue  dequeue ≠ deque and do not sound alike  Structure that provides access to both ends  Combines Stack & Queue concepts  Is also able to add elements to start Deque ADT

15 public interface Deque extends Collection { /* front() */ public E getFirst() throws EmptyDequeException; /* top() */ public E getLast() throws EmptyDequeException; /* dequeue() */ public E removeFirst() throws EmptyDequeException; /* pop() */ public E removeLast() throws EmptyDequeException; /* push() or enqueue() */ public addLast(E elem); /* brand new method! */ public addFirst(E elem); } Deque Interface

16 VIPs versus Losers

17  Class defines fields aliased to first & last nodes  Doubly-linked list enables O(1) time for all methods  Add elements by adding new Node at end  Update sentinel’s next or previous to remove element Linked-list based Deque head rear ØØ

18  Class defines fields aliased to first & last nodes  Doubly-linked list enables O(1) time for all methods  Add elements by adding new Node at end  Update sentinel’s next or previous to remove element Linked-list based Deque head rear ØØ retVal

19  Class defines fields aliased to first & last nodes  Doubly-linked list enables O(1) time for all methods  Add elements by adding new Node at end  Update sentinel’s next or previous to remove element Linked-list based Deque head rear ØØ retVal

20  Class defines fields aliased to first & last nodes  Doubly-linked list enables O(1) time for all methods  Add elements by adding new Node at end  Update sentinel’s next or previous to remove element Linked-list based Deque head rear ØØ retVal

21  Class defines fields aliased to first & last nodes  Doubly-linked list enables O(1) time for all methods  Add elements by adding new Node at end  Update sentinel’s next or previous to remove element Linked-list based Deque head rear ØØ newElem

22  Class defines fields aliased to first & last nodes  Doubly-linked list enables O(1) time for all methods  Add elements by adding new Node at end  Update sentinel’s next or previous to remove element Linked-list based Deque head rear ØØ newElem newNode

23  Class defines fields aliased to first & last nodes  Doubly-linked list enables O(1) time for all methods  Add elements by adding new Node at end  Update sentinel’s next or previous to remove element Linked-list based Deque head rear ØØ newElem newNode

24  Class defines fields aliased to first & last nodes  Doubly-linked list enables O(1) time for all methods  Add elements by adding new Node at end  Update sentinel’s next or previous to remove element Linked-list based Deque head rear ØØ newElem

25  D EQUES, like Q UEUES, have both ends move f  addFirst & removeFirst moves its f ront index  r  r ear index moved by addLast & removeLast  Ends of a array-based D EQUE like clock time  Identical to Queue and how it works, except…  …occasionally need to subtract from index, also Circular Access q r f

26  D EQUES, like Q UEUES, have both ends move f  addFirst & removeFirst moves its f ront index  r  r ear index moved by addLast & removeLast  Ends of a array-based D EQUE like clock time  Identical to Queue and how it works, except…  …occasionally need to subtract from index, also Circular Access q f r

27  D EQUES, like Q UEUES, have both ends move f  addFirst & removeFirst moves its f ront index  r  r ear index moved by addLast & removeLast  Ends of a array-based D EQUE like clock time  Identical to Queue and how it works, except…  …occasionally need to subtract from index, also Circular Access q f r

28  D EQUES, like Q UEUES, have both ends move f  addFirst & removeFirst moves its f ront index  r  r ear index moved by addLast & removeLast  Ends of a array-based D EQUE like clock time  Identical to Queue and how it works, except…  …occasionally need to subtract from index, also Circular Access q f r

29  D EQUES, like Q UEUES, have both ends move f  addFirst & removeFirst moves its f ront index  r  r ear index moved by addLast & removeLast  Ends of a array-based D EQUE like clock time  Identical to Queue and how it works, except…  …occasionally need to subtract from index, also Circular Access q f r

30  D EQUES, like Q UEUES, have both ends move f  addFirst & removeFirst moves its f ront index  r  r ear index moved by addLast & removeLast  Ends of a array-based D EQUE like clock time  Identical to Queue and how it works, except…  …occasionally need to subtract from index, also Circular Access q f r

31  D EQUES, like Q UEUES, have both ends move f  addFirst & removeFirst moves its f ront index  r  r ear index moved by addLast & removeLast  Ends of a array-based D EQUE like clock time  Identical to Queue and how it works, except…  …occasionally need to subtract from index, also Circular Access q f r

32  D EQUES, like Q UEUES, have both ends move f  addFirst & removeFirst moves its f ront index  r  r ear index moved by addLast & removeLast  Ends of a array-based D EQUE like clock time  Identical to Queue and how it works, except…  …occasionally need to subtract from index, also Circular Access q f r

33  D EQUES, like Q UEUES, have both ends move f  addFirst & removeFirst moves its f ront index  r  r ear index moved by addLast & removeLast  Ends of a array-based D EQUE like clock time  Identical to Queue and how it works, except…  …occasionally need to subtract from index, also Circular Access q f r

34  D EQUES, like Q UEUES, have both ends move f  addFirst & removeFirst moves its f ront index  r  r ear index moved by addLast & removeLast  Ends of a array-based D EQUE like clock time  Identical to Queue and how it works, except…  …occasionally need to subtract from index, also Circular Access q f r

35  D EQUES, like Q UEUES, have both ends move f  addFirst & removeFirst moves its f ront index  r  r ear index moved by addLast & removeLast  Ends of a array-based D EQUE like clock time  Identical to Queue and how it works, except…  …occasionally need to subtract from index, also Circular Access q f r

36  D EQUES, like Q UEUES, have both ends move f  addFirst & removeFirst moves its f ront index  r  r ear index moved by addLast & removeLast  Ends of a array-based D EQUE like clock time  Identical to Queue and how it works, except…  …occasionally need to subtract from index, also Circular Access q f r

37 Array-based D EQUE Operations  Uses property of clock math  Remainder of result is all that matters  But the values sign is also important  -1 % 4 == -1, for example

38 Array-based D EQUE Operations  To get this to work, use a cheap trick  Adding size of the array does not change result (-1 + 6) % 6 (3 + 6) % 6 = 5 % 6= 9 % 6 = 5= 3

39 Your Turn  Get into your groups and complete activity

40 For Next Lecture  Read GT chapter 5 for Monday’s class  Consider relationships between 3 ADTs  How are they alike? Different?  When & how would we use each of them?  Week #9 weekly assignment due on Tuesday  Midterm #2  Midterm #2 will be in class on Wednesday


Download ppt "Question of the Day  Two English words change their pronunciation when their first letter is capitalized. What are they?"

Similar presentations


Ads by Google