repositories
/
TD_C.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
TP 7 exo1: Remove a useless branching in a int* swap function
[TD_C.git]
/
TP_7
/
exo1
/
exo1.c
diff --git
a/TP_7/exo1/exo1.c
b/TP_7/exo1/exo1.c
index b57e2ac794b94aa56b6209d46d1a23b852f724cf..6509b0635333c8196cc7540b67f888bd9ab6c8c3 100644
(file)
--- a/
TP_7/exo1/exo1.c
+++ b/
TP_7/exo1/exo1.c
@@
-17,11
+17,9
@@
void xorSwap (int *v1, int *v2) {
}
void swap(int* v1, int* v2) {
}
void swap(int* v1, int* v2) {
- if (v1 != v2) {
- int tmp = *v1;
- *v1 = *v2;
- *v2 = tmp;
- }
+ int tmp = *v1;
+ *v1 = *v2;
+ *v2 = tmp;
}
void displayArray(int* array, int count) {
}
void displayArray(int* array, int count) {
@@
-49,7
+47,6
@@
void sortArray(int* array, int length) {
do {
rt = sortFirst(array, length);
} while (rt);
do {
rt = sortFirst(array, length);
} while (rt);
-
}
int main() {
}
int main() {
@@
-72,8
+69,8
@@
int main() {
printf("\nView array content unsorted:\n");
displayArray(tab, tab_length);
printf("\nView array content unsorted:\n");
displayArray(tab, tab_length);
- sortArray(tab, tab_length);
printf("\nNow, sorting the array...\n");
printf("\nNow, sorting the array...\n");
+ sortArray(tab, tab_length);
printf("\nView array content sorted:\n");
displayArray(tab, tab_length);
printf("\nView array content sorted:\n");
displayArray(tab, tab_length);