Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SDA
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julien David
SDA
Commits
3f2725fd
Commit
3f2725fd
authored
5 years ago
by
david
Browse files
Options
Downloads
Patches
Plain Diff
Ajout des fonctions augmentations et reudction capacité c++
parent
4217b128
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
TP1/CPP/arraylist.hpp
+20
-6
20 additions, 6 deletions
TP1/CPP/arraylist.hpp
with
20 additions
and
6 deletions
TP1/CPP/arraylist.hpp
+
20
−
6
View file @
3f2725fd
...
...
@@ -29,9 +29,9 @@ public:
*/
bool
append
(
P
x
){
bool
memory_allocation
=
false
;
if
(
enlarg
ing
_capacity
()
){
if
(
do_we_need_to_
enlarg
e
_capacity
()
){
memory_allocation
=
true
;
data
.
reserve
(
data
.
capacity
()
*
2
)
;
enlarge_
capacity
();
}
data
.
push_back
(
x
);
return
memory_allocation
;
...
...
@@ -47,9 +47,9 @@ public:
bool
pop_back
(){
bool
memory_reduction
=
false
;
if
(
!
data
.
empty
()){
if
(
reduc
ing
_capacity
()
){
if
(
do_we_need_to_
reduc
e
_capacity
()
){
memory_reduction
=
true
;
data
.
reserve
(
data
.
capacity
()
/
2
)
;
reduce_
capacity
();
}
data
.
pop_back
();
}
...
...
@@ -81,18 +81,32 @@ private:
Cette fonction détermine la règle selon laquelle un espace mémoire plus grand sera alloué ou non.
@returns true si le tableau doit être agrandi, false sinon.
*/
bool
enlarg
ing
_capacity
(){
bool
do_we_need_to_
enlarg
e
_capacity
(){
return
data
.
size
()
>=
(
data
.
capacity
()
*
3
)
/
4
;
}
/**
Cette fonction augmente la capacité du tableau.
*/
void
enlarge_capacity
(){
data
.
reserve
(
data
.
capacity
()
*
2
);
}
/**
Cette fonction détermine la règle selon laquelle un espace mémoire plus petit sera alloué ou non.
@returns true si le tableau doit être réduit, false sinon.
*/
bool
reduc
ing
_capacity
(){
bool
do_we_need_to_
reduc
e
_capacity
(){
return
data
.
size
()
<=
data
.
capacity
()
/
4
&&
data
.
size
()
>
4
;
}
/**
Cette fonction reduit la capacité du tableau.
*/
void
reduce_capacity
(){
data
.
reserve
(
data
.
capacity
()
/
2
);
}
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment