Skip to content
Snippets Groups Projects
Commit 3f2725fd authored by david's avatar david
Browse files

Ajout des fonctions augmentations et reudction capacité c++

parent 4217b128
No related branches found
No related tags found
No related merge requests found
......@@ -29,9 +29,9 @@ public:
*/
bool append(P x){
bool memory_allocation = false;
if( enlarging_capacity() ){
if( do_we_need_to_enlarge_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( reducing_capacity() ){
if( do_we_need_to_reduce_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 enlarging_capacity(){
bool do_we_need_to_enlarge_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 reducing_capacity(){
bool do_we_need_to_reduce_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 );
}
};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment