Presentation is loading. Please wait.

Presentation is loading. Please wait.

ABSTRACT DATA TYPES Data types, data structures, abstract data types, Java/C++ classes, C++ structs.

Similar presentations


Presentation on theme: "ABSTRACT DATA TYPES Data types, data structures, abstract data types, Java/C++ classes, C++ structs."— Presentation transcript:

1 ABSTRACT DATA TYPES Data types, data structures, abstract data types, Java/C++ classes, C++ structs

2 DATA TYPE A data type of a variable in a programming language refers to the set of values that the variable can take. Example 1: int x; x takes on values from -2147483648 to 2147483647 Example 2: typedef double height; height h; h takes on values from -DBL_MAX to DBL_MAX

3 SIMPLE & AGGREGATE DATA TYPES A simple data type is primitive or scalar data type that takes values from only one set. The simple data type is either built-in (primitively supplied by) the programming language, or is a user- defined simple data type. Examples: built-in: int, double user-defined: height

4 SIMPLE & AGGREGATE DATA TYPES An aggregate data type is an n-tuple of many kinds of simple- or aggregate data types, or a sequence (array) of one kind of simple- or aggregate data type. Example: n-tuple: struct point { double x;double y; int color[3]; }; sequence or array: int a[200]; sequence or array: struct point p[100];

5 DATA STRUCTURES A data structure is data type that is either simple or aggregate, built-in or user-defined, or an organized collection of these, with pointers connecting members of the collection. Example: A binary tree is a collection of nodes (structs), where each node has zero, one, or two pointers to children.

6 Data structures: Binary tree example Each node is a struct with pointer members

7 ABSTRACT DATA TYPE An abstract data type (ADT) consists of a data structure, together with operations (functions or methods) for accessing and modifying the data structure. The individual elements of the data structure of the ADT are called member data, and the operations of the ADT are called member functions.

8 ADT & Information Hiding The ADT implements information hiding: although the programmer- creator of the ADT knows all the details about the member data and member functions, the programmer-user of the ADT need not know the details of the member data and must use the member functions supplied by the creator to access and modify the data structure.

9 Implementation of ADTs Classes and structs: ADTs are implemented in Java using classes, and in C++ using classes and structs. In Java and C++, members of a class are private (hidden) by default. In C++, members of a struct are public by default.

10 Classes and structs: Access to members Private members of a class or struct may only be accessed by member functions, which are normally written by and known only to the programmer-creator of the class or struct.

11 Classes and structs: Access to members Programmer-users of the class or struct can only access public members, and so the creator must provide enough public member data and functions to make the class or struct useful to others, without sacrificing “privacy” of the class or struct.


Download ppt "ABSTRACT DATA TYPES Data types, data structures, abstract data types, Java/C++ classes, C++ structs."

Similar presentations


Ads by Google