Link
back to course outline
Chapter 1 Introduction
What is a data structure?
A data
structure is a systematic way of organizing
and accessing data.
-
Primitive data structures:
int,
float (double), or char.
-
Array:
a
data structure that store collections of data and allow direct
access to the elements by using simple index
operations.
-
Programming defined data structures:
-
Vector:
using
index operations but it can grow
dynamically to meet the runtime demands of the program.
-
Stack:
first in last out.
-
Queue: first come first serve.
-
Link List:
like
a chain, store data by pointers. One can be linked to next or previous
one. This is good for inserting
and deleting.
-
Tree:
a Parent-Child relation for data. It is not a linear list.
This is good for searching data.
Move from ARRAY to Records:
Example of struct
Move struct to class:
Example of class
A house is to a blueprint
as an object is to a class.
ADT Abstract Data Type
(It could be used for any programming language)
-
Abstract Data Type is an abstract model that describes an
interface
between a client (user) and the data.
-
ADT defines
-
the domain and structure of data
-
collection of operations to access the data
-
ADT format
C++ Classes and ADT
-
C++ provides the user-defined class type to represent ADT.
-
Data values:
data member
-
Operations:
member function
-
A class consists of two parts:
-
private: data members,
internal operations
-
public: constructor
function, member function
Definition of Class &
Object
Description of Classes & Objects
Five integers Example Employee Exercise
More Exercise
Pointer
example
String
example
"assignment" operator overload:
(Using operator = instead
of strcpy )
We need to use a string class
in stead of a character array to implement
"assignment"
operator overload.
The difference between a string class and a character
array is dynamic vs. static size.
You must have an exact array size to implement a character
array. However,
a string uses Null, '\0', to terminate itself.
So, the length of string can be flexible.
We will cover "Dynamic Memory" later.
Click here to see the string
class.
Link
back to course outline