Sorting - CIS 1068 Program Design and Abstraction Zhen Jiang CIS Dept. Temple University SERC 347, Main Campus 13/14/2016.

Slides:



Advertisements
Similar presentations
Transparency No. 1 Java Collection API : Built-in Data Structures for Java.
Advertisements

CS 206 Introduction to Computer Science II 09 / 05 / 2008 Instructor: Michael Eckmann.
Collections Chapter Java Collection Frameworks The Java collection framework is a set of utility classes and interfaces. Designed for working with.
Processing Data in Collections Chapter Object Wrappers Collections can only hold objects. Primitive types ( int, double, float, etc.) are not objects.
Exercise 1 Suppose C is a class that implements interfaces I and J. Which of the following Requires a type cast? C c = ……? I i = …..? J j = …..? c =
Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Computer Science 209 Software Development Equality and Comparisons.
Arrays and ArrayLists Ananda Gunawardena. Introduction Array is a useful and powerful aggregate data structure presence in modern programming languages.
Topic 5a – Interfaces Friends share all things. CISC370/Object Oriented Programming with Java.
Using interfaces Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling How would you find the maximum.
Lecture 27 Exam outline Boxing of primitive types in Java 1.5 Generic types in Java 1.5.
Unit 261 Introduction to Searching and Sorting Comparable Interface Comparator Interface Algorithm Complexity Classes Exercises.
© 2006 Pearson Addison-Wesley. All rights reserved16-1 Methods in the List Interface (Part 1 of 16)
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L15 (Chapter 22) Java Collections.
COMP 110 Introduction to Programming Mr. Joshua Stough.
Building Java Programs
Chapter 10 2D Arrays Collection Classes. Topics Arrays with more than one dimension Java Collections API ArrayList Map.
Search - CIS 1068 Program Design and Abstraction
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 22 Lists, Stacks, Queues, and Priority.
Abstract Data Types (ADTs) Data Structures The Java Collections API
Searching Algorithms. The Search Problem Problem Statement: Given a set of data e.g., int [] arr = {10, 2, 7, 9, 7, 4}; and a particular value, e.g.,
Computer Science 209 The Strategy Pattern II: Emulating Higher-Order Functions.
9/4/2015Abstract classes & Interface1 Object Oriented Design and Programming II Chapter 10 Abstract classes and Interfaces.
CS 46B: Introduction to Data Structures July 7 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak
Part 2. Searching Arrays Looking for a specific element in an array E.g., whether a certain score (85) is in a list of scores Linear search Binary search.
Building Java Programs Chapter 13 Searching reading: 13.3.
Search - CIS 1068 Program Design and Abstraction Zhen Jiang CIS Dept. Temple University SERC 347, Main Campus 19/23/2015.
Teach.NET Workshop Series Track 4: AP Computer Science with.NET and J#
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
Mason Vail.  A data type definition – “blueprint for objects”  Includes properties and/or methods ◦ “instance” data / methods – specific to one object.
The Java Collections Framework (JCF) Introduction and review 1.
Data structures and algorithms in the collection framework 1 Part 2.
CS 106 Introduction to Computer Science I 04 / 20 / 2007 Instructor: Michael Eckmann.
Recitation 4 Abstract classes, Interfaces. A Little More Geometry! Abstract Classes Shape x ____ y ____ Triangle area() base____ height ____ Circle area()
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
Problem Solving using the Java Programming Language May 2010 Mok Heng Ngee Day 5: Arrays.
Arrays of Objects 1 Fall 2012 CS2302: Programming Principles.
CS 46B: Introduction to Data Structures July 9 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak
Data Design and Implementation. Definitions of Java TYPES Atomic or primitive type A data type whose elements are single, non-decomposable data items.
School of Engineering and Computer Science, Victoria University of Wellington COMP 103 Linked Structures.
Decision Making - CIS 1068 Program Design and Abstraction Zhen Jiang CIS Dept. Temple University SERC 347, Main Campus 10/27/20151.
Computer Science 209 Software Development Java Collections.
CIS 068 Welcome to CIS 068 ! Lesson 10: Data Structures.
SortingBigOh ASFA AP Computer Science A. Big-O refers to the order of an algorithm runtime growth in relation to the number of items I. O(l) - constant.
ArrayList Class An ArrayList is an object that contains a sequence of elements that are ordered by position. An ArrayList is an object that contains a.
Introduction to Generics
CS-2851 Dr. Mark L. Hornick 1 Generic Java Classes Implementing your own generic classes.
Practical Session 4 Java Collections. Outline Working with a Collection The Collection interface The Collection hierarchy Case Study: Undoable Stack The.
Abstract Classes and Interfaces Chapter 9 CSCI 1302.
AITI Lecture 18 Introduction to Data Structure, Stack, and Queue Adapted from MIT Course 1.00 Spring 2003 Lecture 23 and Tutorial Note 8 (Teachers: Please.
Chapter 6 Interfaces. Class Status CU will be close for winter break from Dec. 22. till Jan.2 We have 3 classes left after tonight (Jan 8,15, and 22)
Array - CIS 1068 Program Design and Abstraction Zhen Jiang CIS Dept. Temple University SERC 347, Main Campus 12/19/20151.
Recitation 7 Collections. Array List and Linked List Array List and Linked List are implementations of the same interface: List. As a result, they have.
Searching and Sorting 14ACEHRPT Copyright © 2011 by Maria Litvin, Gary Litvin, and Skylight Publishing. All rights reserved. Java Methods Object-Oriented.
Typecasting References Computer Science 3 Gerb Reference: Objective: Understand how to use the Object class in Java in the context of ArrayLists.
Attribute - CIS 1068 Program Design and Abstraction Zhen Jiang CIS Dept. Temple University SERC 347, Main Campus 12/24/2016.
1 Copyright © 2011 Tata Consultancy Services Limited COLLECTIONS By TEAM 5 Rajendhiran Sivan Christi Yashwanth Bijay Smruthi Satyajit.
Arrays (part 2) 1 -Based on slides from Deitel & Associates, Inc. - Revised by T. A. Yang.
3/21/2016IT 2751 Tow kinds of Lists Array What can be done? What can be easily done? student 1 student 2 student 3 student 4 Linked List student 2 student.
Notices Assn 2 is due Friday, 7pm. Moodle quiz next week – written in the lab as before. Everything up to and including Thursday’s lecture: Big Topics.
Sixth Lecture ArrayList Abstract Class and Interface
University of Central Florida COP 3330 Object Oriented Programming
Instance Method Review - CIS 1068 Program Design and Abstraction
null, true, and false are also reserved.
Arrays and Collections
Object-Oriented Programming Paradigm
Lexical Ordering and Sorting
Instance Method – CSC142 Computer Science II
Subtype Substitution Principle
Presentation transcript:

Sorting - CIS 1068 Program Design and Abstraction Zhen Jiang CIS Dept. Temple University SERC 347, Main Campus 13/14/2016

Table of Contents Introduction to sorting in Java Types of things you can sort Exercise 23/14/2016

Mechanics of Sorting in Java Java has built-in ways to sort arrays and ArrayLists: Arrays.sort(myArray); Collections.sort(myArrayList); Note that these are static methods in the Arrays and Collections classes, NOT instance methods! NOT: myArray.sort(); NOT: myArrayList.sort();

temperatureArray : After Arrays.sort(temperatureArray) :

temperatureArrayList : After Collections.sort(temperatureArrayList) :

Types of things you can sort The Arrays.sort() method applies to arrays, but arrays have types. E.g., int[], double[], Object[], Point[] Arrays.sort() can sort: any primitive array type any Object array type that implements the Comparable interface.

The Collections.sort() method applies to ArrayLists, but ArrayLists have types. E.g., ArrayList, ArrayList, ArrayList Likewise, Collections.sort() can sort: ArrayList, if T implements the Comparable interface

Exercise 83/14/2016 Insertion sorting and its implementation Partial insertion sorting and its implementation 2 nd prize?

3/14/20169 public static int SecondPrize (int [ ] x){ int p1, p2; if (x.length x[p1]){ p2 = p1; p1 = i;} else if (v>x[p2]){ p2 = i;} } return p2; }

103/14/2016 Partial insertion sorting and its implementation 3 rd prize?