Java Collections to STL

Similar documents
Sequences in the C++ STL

Linked Lists: Implementation Sequences in the C++ STL

CHAPTER 4 ESSENTIAL DATA STRUCTRURES

Cours de C++ Utilisations des conteneurs

Java SE 8 Programming

Introduction to Data Structures

C++ Programming Language

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

Curriculum Map. Discipline: Computer Science Course: C++

An Incomplete C++ Primer. University of Wyoming MA 5310

Thomas Jefferson High School for Science and Technology Program of Studies Foundations of Computer Science. Unit of Study / Textbook Correlation

Lecture 2: Data Structures Steven Skiena. skiena

CompuScholar, Inc. Alignment to Utah's Computer Programming II Standards

Java 6 'th. Concepts INTERNATIONAL STUDENT VERSION. edition

Data Structures Using C++ 2E. Chapter 5 Linked Lists

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

JAVA COLLECTIONS FRAMEWORK

BCS2B02: OOP Concepts and Data Structures Using C++

10CS35: Data Structures Using C

KITES TECHNOLOGY COURSE MODULE (C, C++, DS)

Iterator Pattern. CSIE Department, NTUT Chien-Hung Liu. Provide a way to access the elements of an aggregate object sequentially

Introduction to Programming System Design. CSCI 455x (4 Units)

DATA STRUCTURES USING C

WORKSPACE WEB DEVELOPMENT & OUTSOURCING TRAINING CENTER

Why you shouldn't use set (and what you should use instead) Matt Austern

AP Computer Science A - Syllabus Overview of AP Computer Science A Computer Facilities

Glossary of Object Oriented Terms

Integrating the C++ Standard Template Library Into the Undergraduate Computer Science Curriculum

Chapter 8: Bags and Sets

Functions and Parameter Passing

C++ INTERVIEW QUESTIONS

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Chapter 2: Algorithm Discovery and Design. Invitation to Computer Science, C++ Version, Third Edition

Linked Lists, Stacks, Queues, Deques. It s time for a chainge!

The C Programming Language course syllabus associate level

Structural Design Patterns Used in Data Structures Implementation

Lewis, Loftus, and Cocking. Java Software Solutions for AP Computer Science 3rd Edition. Boston, Mass. Addison-Wesley, 2011.

Solving Problems Recursively

Lecture 9. Semantic Analysis Scoping and Symbol Table

recursion, O(n), linked lists 6/14

PES Institute of Technology-BSC QUESTION BANK

Java EE Web Development Course Program

Efficient Data Structures for Decision Diagrams

ECE 250 Data Structures and Algorithms MIDTERM EXAMINATION /5:15-6:45 REC-200, EVI-350, RCH-106, HH-139

Module 2 Stacks and Queues: Abstract Data Types

Computer Programming I

AP Computer Science AB Syllabus 1

Boolean Expressions, Conditions, Loops, and Enumerations. Precedence Rules (from highest to lowest priority)

Java Software Structures

CS107L Handout 04 Autumn 2007 October 19, 2007 Custom STL-Like Containers and Iterators

Questions 1 through 25 are worth 2 points each. Choose one best answer for each.

Multichoice Quetions 1. Atributes a. are listed in the second part of the class box b. its time is preceded by a colon. c. its default value is

Object Oriented Software Design II

Object Oriented Programming With C++(10CS36) Question Bank. UNIT 1: Introduction to C++

Java the UML Way: Integrating Object-Oriented Design and Programming

Fundamentals of Java Programming

Symbol Tables. Introduction

Pseudo code Tutorial and Exercises Teacher s Version

Bevezetés a C++ Standard Template Library-be

Memory management. Announcements. Safe user input. Function pointers. Uses of function pointers. Function pointer example

Java SE 7 Programming

Common Data Structures

C++ Support for Abstract Data Types

Quiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s

C# Cookbook. Stephen Teilhet andjay Hilyard. O'REILLY 8 Beijing Cambridge Farnham Köln Paris Sebastopol Taipei Tokyo '"J""'

Computing Concepts with Java Essentials

Java Application Developer Certificate Program Competencies

Basic Programming and PC Skills: Basic Programming and PC Skills:

Iterators. Provides a way to access elements of an aggregate object sequentially without exposing its underlying representation.

#820 Computer Programming 1A

Practical Session 4 Java Collections

ADVANCED SCHOOL OF SYSTEMS AND DATA STUDIES (ASSDAS) PROGRAM: CTech in Computer Science

Java SE 7 Programming

COMPUTER SCIENCE (5651) Test at a Glance

Java SE 7 Programming

El Dorado Union High School District Educational Services

Android Application Development Course Program

Object Oriented Software Design II

1/20/2016 INTRODUCTION

Heaps & Priority Queues in the C++ STL 2-3 Trees

Java (12 Weeks) Introduction to Java Programming Language

Lab 2: Swat ATM (Machine (Machine))

ALLIED PAPER : DISCRETE MATHEMATICS (for B.Sc. Computer Technology & B.Sc. Multimedia and Web Technology)

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.

The Smalltalk Programming Language. Beatrice Åkerblom

CMPT 183 Foundations of Computer Science I

Lab Experience 17. Programming Language Translation

Storage Classes CS 110B - Rule Storage Classes Page 18-1 \handouts\storclas

Moving from CS 61A Scheme to CS 61B Java

Overview. What is software testing? What is unit testing? Why/when to test? What makes a good test? What to test?

An Empirical Analysis of the Java Collections Framework Versus the C++ Standard Template Library

Operator Overloading. Lecture 8. Operator Overloading. Running Example: Complex Numbers. Syntax. What can be overloaded. Syntax -- First Example

CS Standards Crosswalk: CSTA K-12 Computer Science Standards and Oracle Java Programming (2014)

What Is Recursion? Recursion. Binary search example postponed to end of lecture

Cpt S 223. School of EECS, WSU

Knowledge, Certification, Networking

Sample Syllabus (C++) CSCI 1301 Introduction to Programming Principles

Stack machines The MIPS assembly language A simple source language Stack-machine implementation of the simple language Readings:

7.1 Our Current Model

Transcription:

Java Collections to STL What s the difference between ArrayList and vector How to access each element? Safety and the kitchen sink What happens with t[21] on a 21-element vector? Part of STL means crufty code (whose viewpoint?) Differences in wordlines.cpp and wordlines.java Map compared to map, what other kinds of maps? Sets and vectors, which is easier to use? Anything not clear in either program? Are these programs object-oriented? Software Design 1.1

Standard Libraries In C++ there is the Standard Library, formerly known as the Standard Template Library or STL Emphasizes generic programming (using templates) Write a sorting routine, the implementation depends on Elements being comparable Elements being assignable We should be able to write a routine not specific to int, string or any other type, but to a generic type that supports being comparable/assignable In C++ a templated function/class is a code-factory, generates code specific to a type at compile time Arguably hard to use and unsafe Software Design 1.2

STL concepts Container: stores objects, supports iteration over the objects Containers may be accessible in different orders Containers may support adding/removing elements e.g., vector, map, set, deque, list, multiset, multimap Iterator: interface between container and algorithm Point to objects and move through a range of objects Many kinds: input, forward, random access, bidirectional Syntax is pointer like, analogous to (low-level) arrays Algorithms find, count, copy, sort, shuffle, reverse, Software Design 1.3

Iterator specifics An iterator is dereferenceable, like a pointer *it is the object an iterator points to An iterator accesses half-open ranges, [first..last), it can have a value of last, but then not dereferenceable Analogous to built-in arrays as we ll see, one past end is ok An iterator can be incremented to move through its range Past-the-end iterators not incrementable vector<int> v; for(int k=0; k < 23; k++) v.push_back(k); vector<int>::iterator it = v.begin(); while (it!= v.end()) { cout << *v << endl; v++;} Software Design 1.4

From Java to STL iterators In Java Iterator is an interface Collection(s) are required to have iterators, these are used in some operations like max, min, construct vector, Related to STL as algorithm glue, but very different In STL an iterator is a concept, there are refinements Input, output, forward, bidirectional, random access A forward iterator is an input iterator and an output iterator The iterator may be immutable (or const)---read only Refinements not implemented by inheritance, but by design, contract, and subsequently implementation What happens if you try to implement an STL iterator? Software Design 1.5

Iterator as Pattern (GOF) Provides access to elements of aggregate object sequentially without exposing aggregate s representation Support multiple traversals Supply uniform interface for different aggregates: this is polymorphic iteration (see C++ and Java) Solution: tightly coupled classes for storing and iterating Aggregate sometimes creates iterator (Factory pattern) Iterator knows about aggregate, maintains state Forces and consequences Who controls iteration (internal iterator, apply in MultiSet)? Who defines traversal method? Robust in face of insertions and deletions? Software Design 1.6

STL overview STL implements generic programming in C++ Container classes, e.g., vector, stack, deque, set, map Algorithms, e.g., search, sort, find, unique, match, Iterators: pointers to beginning and one past the end Function objects: less, greater, comparators Algorithms and containers decoupled, connected by iterators Why is decoupling good? Extensible: create new algorithms, new containers, new iterators, etc. Syntax of iterators reflects array/pointer origins, an array can be used as an iterator Software Design 1.7

STL examples: wordlines.cpp How does an iterator work? Start at beginning, iterate until end: use [first..last) interval Pointer syntax to access element and make progress vector<int> v; // push elements vector<int>::iterator first = v.begin(); vector<int>::iterator last = v.end(); while (first < last) { cout << *first << endl; first++; } Will the while loop work with an array/pointer? In practice, iterators aren t always explicitly defined, but passed as arguments to other STL functions Software Design 1.8