03 Sequences
03 Sequences
It consists of:
• Data (representation): (protected or private)
3
What is?
Advantages
• Improves robustness.
• Allows extensibility.
4
What is?
Examples:
• ADT Career.
• ADT Library.
• ADT Vehicle.
5
DESIGN
Concept
• ADT’s design:
https://web.archive.org/web/20130207170133/http://
www.inf.ethz.ch/personal/wirth/books/AlgorithmE0/ 6
DESIGN
Template
• Name ADT Career ADT
• Minimum data set: • Minimum data set:
• Name value(variable); data type; • name; string; career identification
description. • numSt; whole; number of students
• … enrolled.
7
DESIGN
Diagram of relationship between ADT’s
Note:
8
IMPLEMENTATION
Alternatives
• Structure.
• Using libraries:
• .h → interface, method signature.
• .cpp → implementation
9
IMPLEMENTATION
Op1 : Struct
struct Carrera{
std::string nombre; struct Carrera{
unsigned long numEst; std::string nombre;
}; unsigned long numEst;
.cpp .cpp
10
IMPLEMENTATION
Op2 : Class (OOP)
class Carrera {
public:
Carrera();
std::string ObtenerNombre();
unsigned long ObtenerNumEst();
void FijarNombre(std::string name);
void AgregarEstud();
void EliminarEstud();
protected:
std::string nombre;
unsigned long numEst;
};
.cpp
11
ADT DESIGN AND IMPLEMENTATION
Summary:
12
ADT DESIGN AND IMPLEMENTATION
Reminder:
13
SEQUENCES
SEQUENCE
Concept
𝑆 = {𝑠1 , 𝑠2 , 𝑠3 , … , 𝑠𝑛 }
1 1 2 3 5 8 13 ...
S0 S1 S2 S3 S4 S5 S6 ...
15
SEQUENCE
Concept
previous
first
S0 S1 S2 S3 S4 S5 S6 S7
last
next
Index
position
16
SEQUENCE
Concept
Sequece 1
S0 S1 S2 S3 S4 S5 S6 S7
Sequence 2 ≠ Sequence 1
S1 S3 S6 S0 S2 S5 S7 S4
17
IMPLEMENTATION
Static array:
Limited to predefined capacity
int miArr[8] =
{1,1,2,3,5,8,13,21};
1 1 2 3 5 8 13 21
1 1 2 3 5 8 13 21 34
18
IMPLEMENTATION
Dynamic Array:
Limited to the capacity with which it is
created.
19
SEQUENCES
Summary:
1. Necessity
20
GENERIC
PROGRAMMING
Templates
GENERIC PROGRAMMING
Concept
Obstacles:
𝑎 = 𝑏 + 𝑐;
22
GENERIC PROGRAMMING
Use of templates
23
GENERIC PROGRAMMING
Template with a data type
24
GENERIC PROGRAMMING
Template with two data types
int i, j = 25;
long l = 4567;
i = sum<int,long> (j,l);
25
GENERIC PROGRAMMING
Template for classes
26
GENERIC PROGRAMMING
Template for classes
27
GENERIC PROGRAMMING
Exercise:
28
GENERIC PROGRAMMING
Exercise :
OpBinaria.h OpBinaria.hxx main.cpp
29
STL
31
STL
Components
32
STL
Components
Espacio para
Imagen, icono o
diagrama
www.bogotobogo.com/cplusplus/stl3_iterators.php
33
STL
Homework
34
Thank you!