Data Structures Goal: organize data Criteria: facilitate efficient storage of data retrieval of data manipulation of data Process: select and design appropriate data types
Examples
Tradeoff
abstract data type (ADT)
implementation of an ADT
Simple Data Types (§2.2)
Boolean data
Character Data
Integer Data
Sign-magnitude representation
Two's complement representation
Biased representation
Problems with Integer Representation Limited Capacity -- a finite number of bits Overflow - addition or multiplication can exceed largest value permitted by storage scheme Underflow - subtraction or multiplication can exceed smallest value permitted by storage scheme Not a perfect representation of (mathematical) integers can only store a finite (sub)range of them
Real Data
Problems with Real Representation
C-Style One-Dimensional Arrays (§2.3)
Declaring arrays in C++
Subscript operator
Array Initialization
Initializations with no array size specified
Addresses
C-Style Multidimensional Arrays
Problems with C-Style Arrays Capacity cannot change. No predefined operations on non-char arrays. ® Must perform bounds checking, size restrictions, ... C-style arrays aren't self-contained. ® Must pass size (and/or capacity) to array-processing functions. Solution (OOP): Encapsulate array, capacity, size, and operations in a class. ® vector
A commercial for OOP: Two programming paradigms Object-oriented: ( C++, Java, and Smalltalk) Focuses on the nouns of a problem's specification Programmers: Determine what objects are needed for a problem and how they should work together to solve the problem. Create types called classes made up ofdata members and function members to operate on the data. Instances of a type (class) are called objects. Procedural: ( C, FORTRAN, and Pascal ) Action-oriented — concentrates on the verbs of a problem's specification Programmers: Identify basic tasks to be performed to solve problem Implement the actions required to do these tasks as subprograms (procedures/functions/subroutines) Group these subprograms into programs/modules/libraries, which together make up a complete system for solving the problem