L15cs211sp07-6up

L15cs211sp07-6up - Abstract Data Types(ADTs Standard ADTs A...

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

View Full Document Right Arrow Icon
Standard ADTs Lecture 15 CS211 – Spring 2007 2 Abstract Data Types (ADTs) y A method for achieving abstraction for data structures and algorithms y ADT = model + operations y Describes what each operation does, but not how it does it y An ADT is independent of its implementation y In Java, an interface corresponds well to an ADT ± The interface describes the operations, but says nothing at all about how they are implemented y Example: Stack interface/ADT public interface Stack { public void push(Object x); public Object pop(); public Object peek(); public boolean isEmpty(); public void makeEmpty(); } 3 Queues & Priority Queues y ADT Queue ± Operations: void enQueue(Object x); Object deQueue(); Object peek(); boolean isEmpty(); void makeEmpty(); y Where used: ± Simple job scheduler (e.g., print queue) ± Wide use within other algorithms y ADT PriorityQueue ± Operations: void insert(Object x); Object getMax(); Object peekAtMax(); boolean isEmpty(); void makeEmpty(); y Where used: ± Job scheduler for OS ± Event-driven simulation ± Can be used for sorting ± Wide use within other algorithms 4 Sets y ADT Set ± Operations: void insert(Object element); boolean contains(Object element); void remove(Object element); boolean isEmpty(); void makeEmpty(); y Where used: ± Wide use within other algorithms y Note: no duplicates allowed ± A “set” with duplicates is sometimes called a multiset or bag 5 Dictionaries y ADT Dictionary ± Operations: void insert(Object key, Object value); void update(Object key, Object value); Object find(Object key); void remove(Object key); boolean isEmpty(); void makeEmpty(); y Think of: key = word; value = definition y Where used: ± Symbol tables ± Wide use within other algorithms 6 Data Structure Building Blocks y 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
Background image of page 1

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

View Full Document Right Arrow Icon
7 Array Implementation of Stack class ArrayStack implements Stack { private Object[] array; //Array that holds the Stack private int index = 0; //First empty slot in Stack
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.

{[ snackBarMessage ]}

Page1 / 4

L15cs211sp07-6up - Abstract Data Types(ADTs Standard ADTs A...

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