This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Applications of SequencesThe Sequence ADT is a basic, general-purpose, data structure for storing an ordered collection of elementsDirect applications:n Generic replacement for stack, queue, vector, or
listn small database (e.g., address book)
Indirect applications:n Building block of more complex data structures
Linked List ImplementationA doubly linked list provides a reasonable implementation of the Sequence ADTNodes implement Position and store:n elementn link to the previous noden link to the next node
Special trailer and header nodestrailerheader nodes/positions
elements
Position-based methods run in constant timeIndex-based methods require searching from header or trailer while keeping track of indices; hence, run in linear time
Iterators (§ 6.3)An iterator abstracts the process of scanning through a collection of elementsMethods of the IteratorADT:n boolean hasNext()n object next()
Extends the concept of Position by adding a traversal capabilityImplementation with an array or singly linked list
An iterator is typically associated with an another data structureWe can augment the Stack, Queue, Vector, List and Sequence ADTs with method:n Iterator iterator()
Potential extension of Iteratorn Backward traversal