Programming in C# Comparison (Sorting)

Slides:



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

Generics Programming in C# Generics CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis.
Generics, Lists, Interfaces
Processing Data in Collections Chapter Object Wrappers Collections can only hold objects. Primitive types ( int, double, float, etc.) are not objects.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics C# Language &.NET Platform 12 th -13 th Lecture Pavel Ježek.
Polymorphism. 3 Fundamental Properties of OO 1. Encapsulation 2. Polymorphism 3. Inheritance These are the 3 building blocks of object-oriented design.
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.
1 Working with References. 2 References Every object variable is a reference to an object Also true when an object is passed as an argument When the object.
Static Members, Structures, Enumerations, Generic Classes, Namespaces Learning & Development Team Telerik Software Academy.
Attributes Programming in C# Attributes CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis.
Equality Programming in C# Equality CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis.
Using interfaces Objects First with Java - A Practical Introduction using BlueJ, © David J. Barnes, Michael Kölling How would you find the maximum.
CSE 143 Lecture 17 Binary Search Trees and Comparable slides created by Ethan Apter
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.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 4 th Ed Chapter Chapter 11 Searching and Sorting with Objects.
Introduction to Searching and Sorting
Equality Programming in C# Equality CSE / ECE 668 Prof. Roger Crawfis.
FEN 2012UCN Technology - Computer Science 1 Data Structures and Collections Principles revisited.NET: –Two libraries: System.Collections System.Collections.Generics.
Windows Forms Programming in C# Windows Forms CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis.
BIM313 – Advanced Programming Techniques Object-Oriented Programming 1.
Data Binding to Controls Programming in C# Data Binding to Controls CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis.
Computer Science 209 The Strategy Pattern I: Comparisons and Layouts.
CS 106 Introduction to Computer Science I 04 / 20 / 2007 Instructor: Michael Eckmann.
Delegates Programming in C# Delegates CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis.
CSE 143 Lecture 15 Binary Search; Comparable reading: 13.2; 10.2 slides created by Marty Stepp
Modern Software Development Using C#.NET Chapter 5: More Advanced Class Construction.
Introduction to LINQ Chapter 11. Introduction Large amounts of data are often stored in a database—an organized collection of data. A database management.
Abstract Classes and Interfaces Chapter 9 CSCI 1302.
7/28/2003 (c) 2003 Orbonyx Corp. All Rights Reserved. GotDotNet – Building Upon the Framework Roy Ogborn, Independent.NET Consultant Orbonyx Corp.
CS 61B Data Structures and Programming Methodology July 2, 2008 David Sun.
Changing Comparison Programming in C# Changing Comparison CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis.
Topic 7 Interfaces I once attended a Java user group meeting where James Gosling (one of Java's creators) was the featured speaker. During the memorable.
CS2 Module 26 Category: OO Concepts Topic: Interfaces Objectives –Interfaces.
Support standard JavaScript code with static typing Encapsulation through classes and modules Support for constructors, properties and.
1 Principles revisited.NET: Two libraries: System.Collections System.Collections.Generics Data Structures and Collections.
Arrays and Indexers Programming in C# Arrays and Indexers CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis.
Collections Dwight Deugo Nesa Matic
More constructors 1. Constructors  recall that a public constructor is what a client uses to create an object  the purpose of a constructor is to initialize.
IST311 / 602 Cleveland State University – Prof. Victor Matos
Programming in C# Properties
Interfaces I once attended a Java user group meeting where James Gosling (Java's inventor) was the featured speaker. During the memorable Q&A session,
Iterators and Comparators
Java Generics Lecture 17 CS2110 – Spring 2017
Topic 7 Interfaces I once attended a Java user group meeting where James Gosling (one of Java's creators) was the featured speaker. During the memorable.
Collections class Method name Description binarySearch(list, value)
Introduction to Searching and Sorting
Lecture 14: binary search and complexity reading:
Introduction to LINQ Chapter 11 10/28/2015 Lect 4 CT1411.
CSE 1030: Implementing Non-Static Features
The compareTo interface
Lecture 15: binary search reading:
Introduction to LINQ Chapter 11.
Ben’s Lecture Cliff Notes
Arrays and Collections
Welcome to CSE 143! Go to pollev.com/cse143.
More About Objects and Methods
COMPUTER 2430 Object Oriented Programming and Data Structures I
Lexical Ordering and Sorting
The Comparable Interface
IST311 / 602 Cleveland State University – Prof. Victor Matos
5. 3 Coding with Denotations
Creating and Modifying Text part 3
Collections class Method name Description binarySearch(list, value)
Subtype Substitution Principle
CMPE212 – Reminders Assignment 2 due next Friday.
CMPE212 – Reminders Assignment 4 on Inheritance due next Friday.
Advanced .NET Programming I 3rd Lecture
Presentation transcript:

Programming in C# Comparison (Sorting) CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis

Comparison Comparing two instances of a type has many of the same properties and pitfalls as testing for equality. Equality is generally more fussy. Only two protocols for a type providing its own comparison: The IComparable interface The > and < operators

IComparable The IComparable<T> and IComparable interfaces allow for sorting or ordering of a collection. They are used in the Array.Sort method. public interface IComparable <T>{ int CompareTo(T other); // -1 if this < other, 0 if this == other, 1 if this > other } 5.CompareTo(7) => -1 “World”.CompareTo(“Hello”) => 1 32.CompareTo(8*4) => 0

IComparable Classes implementing IComparable are Values types like Int32, Double, DateTime, … The class Enum as base class of all enumeration types The class String Defines a type to be is-a IComparable.

The > and < operators Value types that have a clear context independent concept of less than and greater than should implement the < and > operators. These are compiled statically into the code, making value types more efficient.

Programming in C# Comparison (Sorting) CSE 494R (proposed course for 459 Programming in C#) Prof. Roger Crawfis