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
4217b128
Commit
4217b128
authored
5 years ago
by
david
Browse files
Options
Downloads
Patches
Plain Diff
Ajout des fonctions d'augmentation et de réduction
parent
225fe7ba
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
TP1/C/Makefile
+1
-1
1 addition, 1 deletion
TP1/C/Makefile
TP1/C/arraylist.c
+16
-8
16 additions, 8 deletions
TP1/C/arraylist.c
TP1/C/arraylist.h
+15
-2
15 additions, 2 deletions
TP1/C/arraylist.h
with
32 additions
and
11 deletions
TP1/C/Makefile
+
1
−
1
View file @
4217b128
CC
=
gcc
CXXFLAGS
=
-Wall
-ansi
--pedantic
CXXFLAGS
=
-Wall
-ansi
--pedantic
-O3
CPP_O_FILE
=
arraylist.o analyzer.o main.o
LIB
=
-lm
...
...
This diff is collapsed.
Click to expand it.
TP1/C/arraylist.c
+
16
−
8
View file @
4217b128
...
...
@@ -21,10 +21,9 @@ void arraylist_destroy(arraylist_t * a){
char
arraylist_append
(
arraylist_t
*
a
,
int
x
){
char
memory_allocation
=
FALSE
;
if
(
a
!=
NULL
){
if
(
arraylist_enlarg
ing
_capacity
(
a
)
){
if
(
arraylist_
do_we_need_to_
enlarg
e
_capacity
(
a
)
){
memory_allocation
=
TRUE
;
a
->
capacity
*=
2
;
a
->
data
=
(
int
*
)
realloc
(
a
->
data
,
sizeof
(
int
)
*
a
->
capacity
);
arraylist_enlarge_capacity
(
a
);
}
a
->
data
[
a
->
size
++
]
=
x
;
}
...
...
@@ -34,10 +33,9 @@ char arraylist_append(arraylist_t * a, int x){
char
arraylist_pop_back
(
arraylist_t
*
a
){
char
memory_reduction
=
FALSE
;
if
(
a
!=
NULL
&&
a
->
size
>
0
){
if
(
arraylist_reduc
ing
_capacity
(
a
)
){
if
(
arraylist_
do_we_need_to_
reduc
e
_capacity
(
a
)
){
memory_reduction
=
TRUE
;
a
->
capacity
/=
2
;
a
->
data
=
(
int
*
)
realloc
(
a
->
data
,
sizeof
(
int
)
*
a
->
capacity
);
arraylist_reduce_capacity
(
a
);
}
a
->
size
--
;
}
...
...
@@ -57,10 +55,20 @@ size_t arraylist_get_size(arraylist_t * a){
return
(
a
!=
NULL
)
?
a
->
size
:
-
1
;
}
char
arraylist_enlarg
ing
_capacity
(
arraylist_t
*
a
){
char
arraylist_
do_we_need_to_
enlarg
e
_capacity
(
arraylist_t
*
a
){
return
(
a
->
size
>=
(
a
->
capacity
*
3
)
/
4
)
?
TRUE
:
FALSE
;
}
char
arraylist_reducing_capacity
(
arraylist_t
*
a
){
void
arraylist_enlarge_capacity
(
arraylist_t
*
a
){
a
->
capacity
*=
2
;
a
->
data
=
(
int
*
)
realloc
(
a
->
data
,
sizeof
(
int
)
*
a
->
capacity
);
}
char
arraylist_do_we_need_to_reduce_capacity
(
arraylist_t
*
a
){
return
(
a
->
size
<=
a
->
capacity
/
4
&&
a
->
size
>
4
)
?
TRUE
:
FALSE
;
}
void
arraylist_reduce_capacity
(
arraylist_t
*
a
){
a
->
capacity
/=
2
;
a
->
data
=
(
int
*
)
realloc
(
a
->
data
,
sizeof
(
int
)
*
a
->
capacity
);
}
This diff is collapsed.
Click to expand it.
TP1/C/arraylist.h
+
15
−
2
View file @
4217b128
...
...
@@ -77,14 +77,27 @@ size_t arraylist_get_size(arraylist_t * a);
@param a est un pointeur vers un tableau.
@returns VRAI si le tableau doit être agrandi, FAUX sinon.
*/
char
arraylist_enlarging_capacity
(
arraylist_t
*
a
);
char
arraylist_do_we_need_to_enlarge_capacity
(
arraylist_t
*
a
);
/**
Cette fonction augmente la capacité du tableau.
@param a est un pointeur vers un tableau.
*/
void
arraylist_enlarge_capacity
(
arraylist_t
*
a
);
/**
Cette fonction détermine la règle selon laquelle un espace mémoire plus petit sera alloué ou non.
@param a est un pointeur vers un tableau.
@returns VRAI si le tableau doit être réduit, FAUX sinon.
*/
char
arraylist_reducing_capacity
(
arraylist_t
*
a
);
char
arraylist_do_we_need_to_reduce_capacity
(
arraylist_t
*
a
);
/**
Cette fonction réduit la capacité du tableau.
@param a est un pointeur vers un tableau.
*/
void
arraylist_reduce_capacity
(
arraylist_t
*
a
);
#endif
...
...
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