CS 280 Data Structures - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

CS 280 Data Structures

Description:

CS 280. Data Structures. Professor John Peterson. Netbeans Magic ... 2 can be done much more easily if you use the refactoring menu on NetBeans. ... – PowerPoint PPT presentation

Number of Views:11
Avg rating:3.0/5.0
Slides: 16
Provided by: johnpe2
Learn more at: http://wiki.western.edu
Category:

less

Transcript and Presenter's Notes

Title: CS 280 Data Structures


1
CS 280Data Structures
  • Professor John Peterson

2
Netbeans Magic
  • What you did on Project 2 can be done much more
    easily if you use the refactoring menu on
    NetBeans.
  • Rename Sortable to SortableArrayInt or
    something like that. This is done by
    rightclicking the class name and going to
    refactor -gt rename. When you see the preview of
    the changes, uncheck the edit on the argument to
    the sort in main.
  • Right click on the definition of SortableArrayInt
    and go to refector, then select extract
    interface. Name the extracted interface
    Sortable. Accept all changes.

3
Abstractions
  • When we have general classes of objects that all
    do something similar, we want to use different
    sorts of objects interchangeably.
  • The main way of doing this with Java is an
    interface. This allows us to choose any class
    that implements the interface when we need a
    value denoted by the interface.
  • Review how do interfaces work?

4
Some Abstractions
  • Sorter something that knows how to sort
  • Sortable something that can be sorted with an
    exchange-based sorted
  • Container an array-like object with a size, a
    set, and a get.
  • Comparer something that tells us which object is
    bigger.
  • Each of these abstractions implies a vocabulary.
    We will (generally) extend this vocabulary to
    include name tags (descriptions) so we can see
    whos who.

5
Sorter
  • What does a sorter do?

6
Sorter
  • public interface Sorter
  • public void sort(Sortable s)
  • public String description()
  • We could put the description in the toString
    too.

7
Sortable
  • Weve already done this one in the last project.
    Id like to add one more method String
    description(). This will allow us to debug a
    little more effectively.

8
Sortable
  • public interface Sortable
  • public int size()
  • public boolean gtr(int i, int j)
  • public void swap(int i, int j)
  • public void report()
  • public String description()

9
Container
  • What does our container have to do?

10
Container
  • To make a good container, we need to use generic
    types so that well know whats inside.
  • How do generic classes work???

11
Indexable
  • What methods are needed in Indexable?

12
Indexable
  • public interface IndexableltTgt
  • public int size()
  • public T get(int i)
  • public void put(int i, T obj)

13
Comparisons
  • We dont know how to compare general types the
    user needs to tell us.
  • How do we do that? An interface which carries a
    comparison function.
  • As with the container, we need generics.

14
Comparable
  • public interface ComparableltTgt
  • public boolean gtr(T x, T y)

15
Project 3
  • This one will be a bit harder!
  • Start early! Ask questions! Get help!
  • Lets Look
Write a Comment
User Comments (0)
About PowerShow.com