DOC PREVIEW
TRINITY CSCI 1321 - Linked Lists and Iterators

This preview shows page 1-2-3 out of 10 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 10 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Linked Lists and Iterators2-24-2004Opening DiscussionWhat did we talk about last class?Do you have any questions about the assignment? Remember that the design is due today.Why would you want to use a singly linked list or any other type for that matter? Sorting linked lists?Code for the Singly Linked ListLet’s review the code for a basic singly linked list. In particular, note the recurring pattern of walking a list. That is a very important pattern for you to recognize though you won’t be specifically using it much in the project.Code for a Doubly Linked ListNow let's look at code for a doubly linked list with a sentinel. You should note that this code is much simpler in many ways because it lacks all the special cases.IteratorsYou have now seen patterns for walking through the elements of an array and a linked list. These are very significant patterns when we are dealing with low level code. However, they are also very different and can’t be easily interchanged. We would like a pattern for walking through the elements of any container, whether it be an array, a linked list, or other things we will discuss later.To do this, we introduce the concept of an iterator.Iterators ContinuedAs the name implies, and iterator lets us iterate through the elements of a container. Java has an Interface called Iterator that has three methods. Let’s go to the Java API to look at those methods.Java also has a similar construct with a less common name called an Enumeration. This was used in older Java libraries.Using an IteratorIf we have some type of container, cont, that can give us an Iterator then we can use the following loop structure to walk through the elements of that container, regardless of the nature of the container.for(Iterator iter=cont.iterator; iter.hasNext(); )What would an Iterator for an array based list look like? How about a linked list?Sorting Linked Lists and Sorted ListsLike arrays, linked lists can be sorted. However, what is easy with each is different. The easiest sorts with linked lists build new lists instead of swapping pieces. (Insertion and Selection are easy.)You can also build lists that are always sorted. These have a different interface and fall into a completely different set of data structures which are associative.Iterator CodeLet's now go and write an iterator for one of our linked list classes.Minute EssayThe Iterator for a list can be a private inner class. How would this work? How can you use it outside of the class if it is private?Remember to generate your design today and put it out on the web. The working code is due Thursday.The midterm is two weeks from today.Read java.awt and


View Full Document

TRINITY CSCI 1321 - Linked Lists and Iterators

Documents in this Course
Recursion

Recursion

11 pages

Iterators

Iterators

10 pages

Actors

Actors

9 pages

Recursion

Recursion

15 pages

Recursion

Recursion

10 pages

Threads

Threads

7 pages

Trees

Trees

11 pages

Load more
Download Linked Lists and Iterators
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Linked Lists and Iterators and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Linked Lists and Iterators 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?