Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Antoine Sauray
Sort
Commits
b5022a60
Commit
b5022a60
authored
Feb 29, 2016
by
Antoine Sauray
Browse files
use of lambda functions
parent
57f5321b
Changes
5
Show whitespace changes
Inline
Side-by-side
include/sort.h
View file @
b5022a60
#ifndef SORT_H
#define SORT_H
void
quicksort
(
int
*
tab
,
int
debut
,
int
fin
,
int
order
);
#include
<stdbool.h>
#include
<stdio.h>
void
quicksort
(
int
*
tab
,
int
debut
,
int
fin
,
bool
(
*
f1Ptr
)(
int
,
int
),
bool
(
*
f2Ptr
)(
int
,
int
));
#endif
\ No newline at end of file
include/utils.h
View file @
b5022a60
...
...
@@ -13,4 +13,10 @@ void init(int* array, int size);
bool
isSorted
(
int
*
array
,
int
size
,
int
order
);
bool
more
(
int
a
,
int
b
);
bool
less
(
int
a
,
int
b
);
bool
descending
(
int
a
,
int
b
);
bool
pair
(
int
a
,
int
b
);
bool
impair
(
int
a
,
int
b
);
#endif
\ No newline at end of file
src/main.c
View file @
b5022a60
...
...
@@ -13,7 +13,14 @@ int main(){
printf
(
"array is not sorted
\n
"
);
}
printArray
(
rands
,
SIZE
);
quicksort
(
rands
,
0
,
SIZE
,
DESCENDING
);
bool
(
*
morePtr
)(
int
,
int
);
morePtr
=
&
more
;
bool
(
*
lessPtr
)(
int
,
int
);
lessPtr
=
&
less
;
quicksort
(
rands
,
0
,
SIZE
,
lessPtr
,
morePtr
);
printArray
(
rands
,
SIZE
);
return
0
;
}
src/sort.c
View file @
b5022a60
...
...
@@ -2,7 +2,7 @@
#include
"../include/sort.h"
void
quicksort
(
int
*
tab
,
int
debut
,
int
fin
,
int
order
){
void
quicksort
(
int
*
tab
,
int
debut
,
int
fin
,
bool
(
*
f1Ptr
)(
int
,
int
),
bool
(
*
f2Ptr
)(
int
,
int
)
){
int
temp
;
int
gauche
=
debut
-
1
;
int
droite
=
fin
+
1
;
...
...
@@ -14,15 +14,8 @@ void quicksort(int *tab, int debut, int fin, int order){
}
while
(
1
){
//while true
if
(
order
>
0
){
do
droite
--
;
while
(
tab
[
droite
]
>
pivot
);
//parcourt du tableau de droite à gauche
do
gauche
++
;
while
(
tab
[
gauche
]
<
pivot
);
//parcourt du tableau de gauche à droite
}
else
if
(
order
<
0
){
do
droite
--
;
while
(
tab
[
droite
]
<
pivot
);
//parcourt du tableau de droite à gauche
do
gauche
++
;
while
(
tab
[
gauche
]
>
pivot
);
//parcourt du tableau de gauche à droite
}
do
droite
--
;
while
((
*
f1Ptr
)(
tab
[
droite
],
pivot
));
//parcourt du tableau de droite à gauche
do
gauche
++
;
while
((
*
f2Ptr
)(
tab
[
gauche
],
pivot
));
//parcourt du tableau de gauche à droite
if
(
gauche
<
droite
){
//si deux éléments sont mal placés, on les permutte
swap
(
int
,
tab
[
gauche
],
tab
[
droite
]);
...
...
@@ -33,7 +26,7 @@ void quicksort(int *tab, int debut, int fin, int order){
}
//récursion
quicksort
(
tab
,
debut
,
droite
,
orde
r
);
quicksort
(
tab
,
droite
+
1
,
fin
,
orde
r
);
quicksort
(
tab
,
debut
,
droite
,
f1Ptr
,
f2Pt
r
);
quicksort
(
tab
,
droite
+
1
,
fin
,
f1Ptr
,
f2Pt
r
);
}
\ No newline at end of file
src/utils.c
View file @
b5022a60
...
...
@@ -21,3 +21,17 @@ bool isSorted(int* array, int size, int order){
}
return
true
;
}
bool
more
(
int
a
,
int
b
){
//printf("%d < %d \n", a, b);
return
a
>
b
;
}
bool
less
(
int
a
,
int
b
){
return
a
<
b
;
}
bool
pair
(
int
a
,
int
b
){
return
true
;
}
bool
impair
(
int
a
,
int
b
){
return
true
;
}
Sam Hoster
@SamHoster
·
Jun 16, 2022
Steps_that_can_make_essay_writing_easier_for_you.pdf
[Steps_that_can_make_essay_writing_easier_for_you.pdf](/uploads/1128882513d1e0c6973e02758a18f89e/Steps_that_can_make_essay_writing_easier_for_you.pdf)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment