CH 7 LIST AND ITERATOR ADTS ACKNOWLEDGEMENT THESE
- Slides: 23
CH 7. LIST AND ITERATOR ADTS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN JAVA, GOODRICH, TAMASSIA AND GOLDWASSER (WILEY 2016)
LIST ADT
EXAMPLE • A sequence of List operations:
ARRAY LISTS • 0 0 1 2 i n
INSERTION • A 0 1 2 i n 0 1 2 o i A A n
ELEMENT REMOVAL • A 0 1 2 o i n 0 1 2 r A A n
PERFORMANCE •
EXERCISE: • Implement the Deque ADT update functions using List functions • Deque update functions: • first(), last(), add. First(e), add. Last(e), remove. First(), remove. Last(), size(), is. Empty() • List functions: • get(i), set(i, e), add(i, e), remove(i), size(), is. Empty()
LIST SUMMARY Array Fixed-Size or Expandable add(i, e), remove(i) get(i), set(i, e) size(), is. Empty() List Singly or Doubly Linked
POSITIONAL LISTS •
POSITIONAL LIST ADT • Accessor methods:
POSITIONAL LIST ADT, 2 • Update methods:
EXAMPLE • A sequence of Positional List operations:
POSITIONAL LIST IMPLEMENTATION prev next • The most natural way to implement a positional list is with a doubly-linked list. header element nodes/positions elements node trailer
INSERTION, E. G. , ADDAFTER(P, E) p A B C p A q B C X p A q B X C
REMOVE(P) p A B C D p D A B C
PERFORMANCE •
POSITIONAL LIST SUMMARY List Singly-Linked first(), last(), add. First(), add. Last(), add. After() add. Before(p, e), erase() size( ), is. Empty() List Doubly- Linked
ITERATORS • An iterator is a software design pattern that abstracts the process of scanning through a sequence of elements, one element at a time.
THE ITERABLE INTERFACE • Java defines a parameterized interface, named Iterable, that includes the following single method: • iterator(): Returns an iterator of the elements in the collection. • An instance of a typical collection class in Java, such as an Array. List, is Iterable (but not itself an iterator); it produces an iterator for its collection as the return value of the iterator() method. • Each call to iterator() returns a new iterator instance, thereby allowing multiple (even simultaneous) traversals of a collection.
THE FOR-EACH LOOP • Java’s Iterable class also plays a fundamental role in support of the “for-each” loop syntax: • is equivalent to:
INTERVIEW QUESTION 1 • Write code to partition a list around a value x, such that all nodes less than x come before all nodes greater than or equal to x. GAYLE LAAKMANN MCDOWELL, "CRACKING THE CODE INTERVIEW: 150 PROGRAMMING QUESTIONS AND SOLUTIONS", 5 TH EDITION, CAREERCUP PUBLISHING, 2011.
INTERVIEW QUESTION 2 • Implement a function to check if a list is a palindrome. GAYLE LAAKMANN MCDOWELL, "CRACKING THE CODE INTERVIEW: 150 PROGRAMMING QUESTIONS AND SOLUTIONS", 5 TH EDITION, CAREERCUP PUBLISHING, 2011.
- Adts, data structures, and problem solving with c++
- Parameterized adts is also known as
- Parameterized adts is also known as
- Adts ukiah
- Iterator inner class java
- Iterator pattern python
- Inorder iterator
- Rapidjson array
- Iterator entwurfsmuster
- Comparator design pattern
- Volcano iterator model
- Zig iterator
- Junit before after
- Code blocks in python
- Introduction and acknowledgement
- What is sequence number and acknowledgement number in tcp
- Technical writing thesis
- Acknowledgement for ppt presentation
- Acknowledgement ppt
- Don't reply all
- Acknowledgement presentation
- Acknowledgement slide
- What is duplicate acknowledgement in tcp
- Acknowledgement slides