16-StandardADTs

16-StandardADTs - Abstract Data Types(ADTs CS/ENGRD 2110...

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

View Full Document Right Arrow Icon
3/29/2011 1 CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2010 Thorsten Joachims Lecture 16: Standard ADTs Abstract Data Types (ADTs) A method for achieving abstraction for data structures and algorithms ADT = model + operations Describes what each operation does, but not how it does it An ADT is independent of its implementation In Java, an interface corresponds well to an ADT The interface describes the operations, but says nothing at all about how they are implemented Example: List interface/ADT public interface List<E> { public void add(int index, E x); public boolean contains(Object o); public E get(int index); } 2 Sets ADT Set Operations: void insert(Object element); boolean contains(Object element); void remove(Object element); boolean isEmpty(); void clear(); Where used: Peg Solver (memoize boards that were visited already) Wide use within other algorithms Note: no duplicates allowed A “set” with duplicates is sometimes called a multiset or bag 3 ADT Queue Operations: void add(Object x); Object poll(); Object peek(); boolean isEmpty(); void clear(); Where used: Simple job scheduler (e.g., print queue) Wide use within other algorithms ADT PriorityQueue Operations: void insert(Object x); Object getMax(); Object peekAtMax(); boolean isEmpty(); void clear(); Where used: Job scheduler for OS Event-driven simulation Can be used for sorting Wide use within other algorithms 4 Stacks ADT Stack Operations: void push(Object element); Object pop(); Object peek(); boolean isEmpty(); void clear(); Where used: Frame stack Wide use within other algorithms 5 Dictionaries ADT Dictionary (aka Map) Operations: void insert(Object key, Object value); void update(Object key, Object value); Object find(Object key); void remove(Object key); boolean isEmpty(); void clear(); Think of: key = word; value = definition Where used: Symbol tables Wide use within other algorithms 6
Background image of page 1

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

View Full DocumentRight Arrow Icon
3/29/2011 2 Data Structure Building Blocks These are implementation “building blocks” that are often used to build more-complicated data structures Arrays Linked Lists (singly linked, doubly linked) Binary Trees Graphs (adjacency matrix, adjacency list) 7 Array Implementation of Stack class ArrayStack implements Stack { private Object[] array; //Array that holds Stack private int index = 0; //First empty slot in Stack public ArrayStack(int maxSize) { array = new Object[maxSize]; } public void push(Object x) { array[index++] = x; }
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/17/2011 for the course CS 2110 taught by Professor Francis during the Spring '07 term at Cornell.

Page1 / 5

16-StandardADTs - Abstract Data Types(ADTs CS/ENGRD 2110...

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

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