Docsity

Data Design - Data Structures - Lecture Slides, Slides of Data Structures and Algorithms

Partial preview of the text

Download Data Design - Data Structures - Lecture Slides and more Slides Data Structures and Algorithms in PDF only on Docsity!

Chapter 2 Data Design and Implementation

  • Lecture

Data Abstraction

  • Separation of a data type ’ s logical properties from its implementation

4

LOGICAL PROPERTIES IMPLEMENTATION

What are the possible values? How can this be done in C++?

What operations will be needed? How can data types be used?

APPLICATION

0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1

REPRESENTATION

Data Encapsulation

  • is the separation of the representation of data from the applications that use the data at a logical level; - a programming language feature that enforces information hiding

5

int y;

y = 25;

Abstract Data Type (ADT)

  • A data type whose properties (domain and

operations) are specified independently of any particular implementation.

Collection ordered in different ways

Communication between the Application Level and Implementation Level

Viewing a library from 3 different levels

  • Application (or user) level: Library of Congress, or Baltimore County Public Library.
  • Logical (or ADT) level: domain is a collection of books; - operations include: check book out, check book in, pay fine, reserve a book.
  • Implementation level: representation of the structure to hold the “ books ” , and the coding for operations.

4 Basic Kinds of ADT Operations

  • Constructor -- creates a new instance (object) of an

ADT.

  • Transformer -- changes the state of one or more of

the data values of an instance.

  • Observer -- allows us to observe the state of one or

more of the data values without changing them.

  • Iterator -- allows us to process all the components in

a data structure sequentially.

Two Forms of Composite Data Types

UNSTRUCTURED

14

Components are not organized with respect to one another.

The organization determines method used to access individual data components.

STRUCTURED

EXAMPLES: EXAMPLES: arrays classes and structs

Records

A record is a composite data type made up of a finite collection of not necessarily homogeneous elements called members or fields****. For example...

16

.year 2008

.maker ‘ h ’‘ o ’‘ n ’‘ d’ ‘ a’ ‘ \0 ’...

.price 18678.

thisCar at Base Address 6000

struct CarType

struct CarType {

int year; char maker[10]; float price;

} ;

CarType thisCar; //CarType variable s CarType myCar;

Valid struct operations

  • Operations valid on an entire struct type variable:

assignment to another struct variable of same type,

pass as a parameter to a function (either by value or by reference),

return as the value of a function.

Pass-by-value

20

CALLING BLOCK

FUNCTION CALLED

sends a copy of the contents of the actual parameter

SO, the actual parameter cannot be changed by the function.