ordered - Computer Science 211 Data Structures Mount...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Computer Science 211 Data Structures Mount Holyoke College Fall 2009 Topic Notes: Ordered Structures We have considered two special-purpose data types, stacks and queues, that are essentially re- stricted versions of the more general structures we considered earlier. While we implemented our stacks and queues using arrays and vectors and linked lists, the in- terfaces to these linear structures limited access to the internal representation, and allowed us to choose an appropriate way to orient the data within the structures to make the operations in the restricted interface as efficient as possible. Now, we consider structures that have another restriction placed on them: that their contents are maintained in some order. These ordered structures may allows us to search among their contents efficiently, or we may want to process the contents in a particular order. These can be implemented using the structures we know so well, but again we will want to restrict the interface so as to guarantee that the ordered nature of the structures is not violated. Ordering objects implies that we have a mechanism for comparing them. Recall that when we discussed sorting algorithms, we said that the elements of the arrays had to be Comparable . Comparable is a Java interface that requires a method: public int compareTo(T item); In one assignment, we extended this idea to the more general Comparator concept, where we could compare objects of any type and according to any criteria, by supplying an appropriate compare method in a Comparator that could compare two given objects. Let’s consider how the Comparable interface and Comparator objects might be of use in defining objects that can be placed into an ordered structure. In particular, let’s begin by consider- ing a Comparable Association . It is an extension of the
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 02/15/2010.

Page1 / 4

ordered - Computer Science 211 Data Structures Mount...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online