Recitation 10 November 3, 2011.

Slides:



Advertisements
Similar presentations
Queues Printer queues Several jobs submitted to printer Jobs form a queue Jobs processed in same order as they were received.
Advertisements

CS Data Structures I Chapter 6 Stacks I 2 Topics ADT Stack Stack Operations Using ADT Stack Line editor Bracket checking Special-Palindromes Implementation.
1 Todays Objectives Announcements Homework #1 is due next week Return Quiz 1 – answers are posted on the Yahoo discussion page site Basic Java Programming.
Java Review Interface, Casting, Generics, Iterator.
1 ADT and Data Structure Example Generics / Parameterized Classes Using a Set Implementing a Set with an Array Example: SetADT interface Example: ArraySet.
COP3538 – Data Structures Using OOP Chapter 4 – Stacks and Queues.
C OMP 110 A RRAYS Instructor: Jason Carter. 2 O UTLINE for loops Arrays.
C OMP 401 D YNAMIC D ISPATCH AND A BSTRACT M ETHODS Instructor: Prasun Dewan.
Stacks CS-240 Dick Steflik. Stacks Last In, First Out operation - LIFO As items are added they are chronologically ordered, items are removed in reverse.
Arrays –Collections (Set, Database, History) Inheritance –inheriting ancestor’s traits –inheriting benefactor’s assets –inheriting instance members( methods/variables)
List Implementations That Use Arrays Chapter 5. 2 Chapter Contents Using a Fixed-Size Array to Implement the ADT List An Analogy The Java Implementation.
CHAPTER 6 Stacks Array Implementation. 2 Stacks A stack is a linear collection whose elements are added and removed from one end The last element to be.
Implementing Stacks Using Arrays CSC 1401: Introduction to Programming with Java Week 14 – Lecture 1 Wanda M. Kunkle.
ObjectEditor Prasun Dewan Comp 114. ObjectEditor Automatic user-interface generation. You only write computation code Separate object to do I/O Main just.
Chapter 14 Queues. First a Review Queue processing Using queues to solve problems – Optimizing customer service simulation – Ceasar ciphers – Palindrome.
Chapter 7 Stacks I CS Data Structures I COSC 2006 April 22, 2017
Data Structures. The Stack: Definition A stack is an ordered collection of items into which new items may be inserted and from which items may be deleted.
CS 2430 Day 26. Announcements Exam #2: Wednesday, April 3 –Review in lab on Tuesday, April 2 –Sample problems sent via .
Java Arrays …………. Java Arrays …………. * arrays are objects in Java * arrays are objects in Java * an array variable is a reference * an array variable is.
Abstract Data Types. What’s on the menu? What’s an abstract data type? How do you implement it? ADT List.
C OMP 401 A DVANCED G ENERICS Instructor: Prasun Dewan.
Object-based Scanning Redo the scanning solutions Monolithic, single class solutions –does UI and scanning No reuse of code.
CS 2430 Day 24. Announcements Quiz this Friday Program 5 posted on Monday Program 4 due date: Friday at 10pm Program 4 grace date: Wednesday at 10pm (don’t.
Chapter 4 ADTs Stack and Queue. 4-2 Formal ADT Specifications The Java interface construct lets us collect together method interfaces into a syntactic.
M180: Data Structures & Algorithms in Java Stacks Arab Open University 1.
Int fact (int n) { If (n == 0) return 1; else return n * fact (n – 1); } 5 void main () { Int Sum; : Sum = fact (5); : } Factorial Program Using Recursion.
Click to edit Master text styles Stacks Data Structure.
Section 2.3 Array-Based StringLog ADT Implementation.
C OMP 401 D YNAMIC D ISPATCH AND V IRTUAL AND A BSTRACT M ETHODS Instructor: Prasun Dewan.
An Array-Based Implementation of the ADT List
Linked Data Structures
Sections 3.4 Formal Specification
Section 2.6 Linked List StringLog ADT Implementation
Sixth Lecture ArrayList Abstract Class and Interface
GC211 Data Structure Lecture 1 Sara Alhajjam.
Stacks.
Implementing ArrayList Part 1
Lists The List ADT.
Arrays and the ArrayList Class The ArrayList Class
Generic array list and casting C&K s7.7
Comp 401 Dynamic Dispatch and Virtual and Abstract Methods
CMSC 341 Lecture 5 Stacks, Queues
Queues 11/9/2018 6:28 PM Queues 11/9/2018 6:28 PM Queues.
Queues 11/16/2018 4:18 AM Queues 11/16/2018 4:18 AM Queues.
Queues 11/16/2018 4:19 AM Queues 11/16/2018 4:19 AM Queues.
Queues.
Explicit and Implicit Type Changes
Selection Sort Find the smallest value in the array. Put it in location zero. Find the second smallest value in the array and put it in location 1. Find.
COMPUTER 2430 Object Oriented Programming and Data Structures I
COMPUTER 2430 Object Oriented Programming and Data Structures I
Arrays of Objects Fall 2012 CS2302: Programming Principles.
Arrays versus ArrayList
CS 2430 Object Oriented Programming and Data Structures I
COMPUTER 2430 Object Oriented Programming and Data Structures I
Arrays of Objects Fall 2012 CS2302: Programming Principles.
Queues: Implemented using Arrays
ساختمان داده ها پشته ها Give qualifications of instructors: DAP
Queues 12/30/2018 9:24 PM Queues 12/30/2018 9:24 PM Queues.
Multidimensional Arrays
Recitation 7 October 7, 2011.
Recitation 6 September 30, 2011.
Recitation 9 October 28, 2011.
Programming II (CS300) Chapter 02: Using Objects Java ArrayList Class
ADT Queue (Array Implementation)
CIS 199 Final Review.
Circular Queues: Implemented using Arrays
Stacks.
5. 3 Coding with Denotations
Getting queues right … finally (?)
A type is a collection of values
Presentation transcript:

Recitation 10 November 3, 2011

Today’s Goals: Learn Generics Practice with Generics

History Interface public interface History { public void addElement(Object element); public Object elementAt (int index); public int size(); }

Generic History Interface public interface History<T> { public void addElement(T element); public T elementAt (int index); public int size(); }

AHistory public class AHistory<T> implements History<T> { public final int MAX_SIZE = 50; Object[] contents = new Object[MAX_SIZE]; int size = 0; public int size() {return size;} public T elementAt (int index) { return (T) contents[index]; } boolean isFull() {return size == MAX_SIZE;} public void addElement(T element) { if (isFull()) System.out.println("Adding item to a full history"); else { contents[size] = element; size++; A single implementation where T = Object is shared by all of its elaborations.

Instantiating A String History History<String> stringHistory = new AHistory<String>(); History<String> stringHistory = new AHistory();

Recitation Specification Download Recitation10.zip from the Recitations page Make changes to the given Stack interface to make it a “generic” interface. (Only change 3 lines) Now implement the interface with a class named AStack which is a generic class. (default size >=200) Internally just create an array of Objects to store the elements Cast to the correct type before returning in the get method. (This will signal a warning, which is okay.) Bonus (for candy): Create a “cool” design using the shape primitives provided, but specify coordinates using functions and loops. Ben will judge.