X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=exo1%2Fexo1.c;h=eef51dbc61831d4219acab57f8b5e30604aa8f5b;hb=39ba1592dca861839f707facb99d315756650a43;hp=8b44ea40af1f93a0284ade71122312c3a0dcd4ea;hpb=b77c2eee8228cc599196120657e503e4146be4b1;p=TD_C.git diff --git a/exo1/exo1.c b/exo1/exo1.c index 8b44ea4..eef51db 100644 --- a/exo1/exo1.c +++ b/exo1/exo1.c @@ -7,7 +7,7 @@ void promptValue(int* addr) { scanf("%d", addr); } -// The efficience of this swap alternative is debatable .. +// The efficiency of this swap alternative is debatable .. void xorSwap (int *v1, int *v2) { if (v1 != v2) { *v1 ^= *v2; @@ -32,11 +32,13 @@ void displayArray(int* array, int count) { bool sortFirst(int* array, int length) { bool rt = false; + // This loop could probably be replaced by a while loop with conditions + // on the array values permutation AND the iteration value, later ... for (int i = 0; i < length-1; i++) { if (array[i] > array[i+1]) { swap(&array[i], &array[i+1]); //xorSwap(&array[i], &array[i+1]); - rt = true; + if (!rt) { rt = true; }; } } return rt; @@ -52,8 +54,10 @@ void sortArray(int* array, int length) { int main() { int tab_length = 10; - // GCC do not like variable sized array, even with the size variable properly initialized - int tab[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + int tab[tab_length]; + for (int i = 0; i < tab_length; i++) { + tab[i] = 0; + } for (int i = 0; i < tab_length; i++) { printf("Enter integer value at array's index[%d]? ", i);