dsa - lecture 03

29
Collections and Generics Dr.Haitham A. El-Ghareeb Information Systems Department Faculty of Computers and Information Sciences Mansoura University [email protected] September 30, 2012 Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 1 / 13

Upload: haitham-a-el-ghareeb

Post on 05-Dec-2014

3.935 views

Category:

Education


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: DSA - Lecture 03

Collections and Generics

Dr.Haitham A. El-Ghareeb

Information Systems DepartmentFaculty of Computers and Information Sciences

Mansoura University

[email protected]

September 30, 2012

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 1 / 13

Page 2: DSA - Lecture 03

Good News

Received: 23 September 2012

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 2 / 13

Page 3: DSA - Lecture 03

Good News

http://www.helghareeb.me/courses/dsa-2012

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 3 / 13

Page 4: DSA - Lecture 03

Collections

A collection is a structured data type that stores data and providesoperations for adding data to the collection.

Operations include:I removing data from the collectionI updating data in the collectionI and operations for setting and returning the values of different

attributes of the collection.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 4 / 13

Page 5: DSA - Lecture 03

Collections

A collection is a structured data type that stores data and providesoperations for adding data to the collection.

Operations include:I removing data from the collectionI updating data in the collectionI and operations for setting and returning the values of different

attributes of the collection.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 4 / 13

Page 6: DSA - Lecture 03

Collections

A collection is a structured data type that stores data and providesoperations for adding data to the collection.

Operations include:

I removing data from the collectionI updating data in the collectionI and operations for setting and returning the values of different

attributes of the collection.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 4 / 13

Page 7: DSA - Lecture 03

Collections

A collection is a structured data type that stores data and providesoperations for adding data to the collection.

Operations include:I removing data from the collection

I updating data in the collectionI and operations for setting and returning the values of different

attributes of the collection.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 4 / 13

Page 8: DSA - Lecture 03

Collections

A collection is a structured data type that stores data and providesoperations for adding data to the collection.

Operations include:I removing data from the collectionI updating data in the collection

I and operations for setting and returning the values of differentattributes of the collection.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 4 / 13

Page 9: DSA - Lecture 03

Collections

A collection is a structured data type that stores data and providesoperations for adding data to the collection.

Operations include:I removing data from the collectionI updating data in the collectionI and operations for setting and returning the values of different

attributes of the collection.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 4 / 13

Page 10: DSA - Lecture 03

Collection Types

Collections can be broken down into two types: linear and nonlinear.

A linear collection is a list of elements where one element follows theprevious element.

Elements in a linear collection are normally ordered by position (first,second, third, etc.).

Nonlinear collections hold elements that do not have positional orderwithin the collection.

An organizational chart is an example of a non- linear collection.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 5 / 13

Page 11: DSA - Lecture 03

Collection Types

Collections can be broken down into two types: linear and nonlinear.

A linear collection is a list of elements where one element follows theprevious element.

Elements in a linear collection are normally ordered by position (first,second, third, etc.).

Nonlinear collections hold elements that do not have positional orderwithin the collection.

An organizational chart is an example of a non- linear collection.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 5 / 13

Page 12: DSA - Lecture 03

Collection Types

Collections can be broken down into two types: linear and nonlinear.

A linear collection is a list of elements where one element follows theprevious element.

Elements in a linear collection are normally ordered by position (first,second, third, etc.).

Nonlinear collections hold elements that do not have positional orderwithin the collection.

An organizational chart is an example of a non- linear collection.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 5 / 13

Page 13: DSA - Lecture 03

Collection Types

Collections can be broken down into two types: linear and nonlinear.

A linear collection is a list of elements where one element follows theprevious element.

Elements in a linear collection are normally ordered by position (first,second, third, etc.).

Nonlinear collections hold elements that do not have positional orderwithin the collection.

An organizational chart is an example of a non- linear collection.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 5 / 13

Page 14: DSA - Lecture 03

Collection Types

Collections can be broken down into two types: linear and nonlinear.

A linear collection is a list of elements where one element follows theprevious element.

Elements in a linear collection are normally ordered by position (first,second, third, etc.).

Nonlinear collections hold elements that do not have positional orderwithin the collection.

An organizational chart is an example of a non- linear collection.

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 5 / 13

Page 15: DSA - Lecture 03

Collection Properties and Methods

Collection Property is the collections Count, which holds the numberof items in the collection.

Collection operations, called methods, include:I Add (for adding a new element to a collection)I Insert (for adding a new element to a collection at a specified index)I Remove (for removing a specified element from a collection)I Clear (for removing all the elements from a collection)I Contains (for determining if a specified element is a member of a

collection)

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 6 / 13

Page 16: DSA - Lecture 03

Collection Properties and Methods

Collection Property is the collections Count, which holds the numberof items in the collection.

Collection operations, called methods, include:I Add (for adding a new element to a collection)I Insert (for adding a new element to a collection at a specified index)I Remove (for removing a specified element from a collection)I Clear (for removing all the elements from a collection)I Contains (for determining if a specified element is a member of a

collection)

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 6 / 13

Page 17: DSA - Lecture 03

Collection Properties and Methods

Collection Property is the collections Count, which holds the numberof items in the collection.

Collection operations, called methods, include:I Add (for adding a new element to a collection)I Insert (for adding a new element to a collection at a specified index)I Remove (for removing a specified element from a collection)I Clear (for removing all the elements from a collection)I Contains (for determining if a specified element is a member of a

collection)

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 6 / 13

Page 18: DSA - Lecture 03

Linear Collections

Direct Access Collections

Sequential Access Collections

Generalized Indexed Collections

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 7 / 13

Page 19: DSA - Lecture 03

Linear Collections

Direct Access Collections

Sequential Access Collections

Generalized Indexed Collections

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 7 / 13

Page 20: DSA - Lecture 03

Linear Collections

Direct Access Collections

Sequential Access Collections

Generalized Indexed Collections

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 7 / 13

Page 21: DSA - Lecture 03

Linear Collections

Direct Access Collections

Sequential Access Collections

Generalized Indexed Collections

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 7 / 13

Page 22: DSA - Lecture 03

Struct

DEMO

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 8 / 13

Page 23: DSA - Lecture 03

Non Linear Collections

Hierarchical Collections

Group Collections

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 9 / 13

Page 24: DSA - Lecture 03

Non Linear Collections

Hierarchical Collections

Group Collections

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 9 / 13

Page 25: DSA - Lecture 03

Non Linear Collections

Hierarchical Collections

Group Collections

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 9 / 13

Page 26: DSA - Lecture 03

My Collection Class

DEMO

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 10 / 13

Page 27: DSA - Lecture 03

Generic Programming

DEMO

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 11 / 13

Page 28: DSA - Lecture 03

Oversimplified Timing Tests

DEMO

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 12 / 13

Page 29: DSA - Lecture 03

Charting in .Net

DEMO

Dr.Haitham A. El-Ghareeb (CIS) Data Structures and Algorithms - 2012 September 30, 2012 13 / 13