Final Exam - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Final Exam

Description:

CSE 503 FRI 12/15/2006. 08:00 AM - 11:00 AM, NSC 205. Quiz on Friday. Dec 1 ... Pink Floyd. Pink Floyd. 3. 1. 2. 3. 4. 5. AC / DC. AC / DC. 1. 0. index. Two lists: ... – PowerPoint PPT presentation

Number of Views:56
Avg rating:3.0/5.0
Slides: 14
Provided by: michael316
Category:
Tags: exam | final | floyd | pink

less

Transcript and Presenter's Notes

Title: Final Exam


1
Final Exam
  • CSE 115, WED 12/13/2006
  • 0330 PM - 0630 PM, NSC 225
  • NOT - ALUMNI 97
  • NOT -
  • CSE 503 FRI 12/15/2006
  • 0800 AM - 1100 AM, NSC 205

2
Quiz on Friday
  • Dec 1
  • Topics debugging, and Timers
  • No Lab 12

3
The List Interface
  • A List, is an array, of indefinite size
  • It grows and shrinks as you add and remove
    elements
  • Two types of lists
  • ArrayList
  • LinkedList
  • import java.util.

4
Two types?
  • An ArrayList is a general purpose array, but with
    list properties
  • certain methods
  • grows and shrinks
  • A LinkedList contains mappings stored with each
    element which virtually sort the array (without
    moving elements around).

5
Two lists
index
AC / DC
AC / DC
1
0
Beatles
Beatles
0
4
1
Incubus
Incubus
4
3
2
Ozzy
Ozzy
2
5
3
Eagles
Eagles
1
2
4
Pink Floyd
Pink Floyd
3
5
6
A general-purpose interface
  • List myList
  • decide later in the code which kind of list
  • myList new ArrayList()
  • or
  • myList new LinkedList()

7
some methods
  • To find the current size of a list we use the
    size method.
  • To empty a list use the clear method.

8
add( ) and get( )
  • add elements with add( )
  • get elements with get( ) - casting required

9
index-based methods
  • add(int index, Object element)        Inserts
    the specified element at the specified position
    in this list
  • set(int index, Object element)       Replaces
    the element at the specified position in this
    list with the specified element.
  • get(int index)           
  • Returns the element at the specified position
    in this list

10
the iterator
  • traverses the list using next( ) and hasNext( )
    methods
  • all Lists have an iterator, just go get it
  • List myList
  • myList new ArrayList()
  • Iterator itr myList.iterator( )
  • while ( itr.hasNext () )
  • ....

11
the Linked List
  • has INTERNAL previous and next fields
  • you dont see them
  • cant manipulate them
  • allows internal speedup of searching and sorting
  • List yourList new ArrayList()
  • List myList new LinkedList()
  • myList is faster

12
the Collection class
  • manages Lists (ArrayLists and LinkedLists)
  • offers a very useful method
  • .sort( List )

13
well, sometimes its easy
  • List myList new ArrayList( )
  • for (x1000 x 0 x x-1)
  • myList.add( x ) // 1000, 999, 998, 997, etc
  • Collections.sort( myList )
  • Collections.sort( myList, Collections.reverseOrder
    () )

whats this?
Write a Comment
User Comments (0)
About PowerShow.com