]>
Piment Noir Git Repositories - TD_C.git/blob - TP_7/exo1/exo1.c
6509b0635333c8196cc7540b67f888bd9ab6c8c3
4 //FIXME: Comment the code !!!
6 void promptValue(int* addr
) {
10 // The efficiency of this swap alternative is debatable ..
11 void xorSwap (int *v1
, int *v2
) {
19 void swap(int* v1
, int* v2
) {
25 void displayArray(int* array
, int count
) {
26 for (int i
= 0; i
< count
; i
++) {
27 printf("Value in array at index[%d]= %d\n", i
, array
[i
]);
31 bool sortFirst(int* array
, int length
) {
33 // This loop could probably be replaced by a while loop with conditions
34 // on the array values permutation AND the iteration value, later ...
35 for (int i
= 0; i
< length
-1; i
++) {
36 if (array
[i
] > array
[i
+1]) {
37 swap(&array
[i
], &array
[i
+1]);
38 //xorSwap(&array[i], &array[i+1]);
39 if (!rt
) { rt
= true; };
45 void sortArray(int* array
, int length
) {
48 rt
= sortFirst(array
, length
);
55 for (int i
= 0; i
< tab_length
; i
++) {
59 for (int i
= 0; i
< tab_length
; i
++) {
60 printf("Enter integer value at array's index[%d]? ", i
);
61 /* En langage C, une ligne doit être terminée par le caractère '\n'. Tant que */
62 /* la ligne n'est pas terminée et que le tampon associé au fichier n'est pas plein, */
63 /* les caractères transmis ne seront pas effectivement écrits mais tout simplement */
64 /* placés dans le tampon. On peut cependant forcer le vidage de ce tampon à l'aide */
65 /* de la fonction fflush. */
70 printf("\nView array content unsorted:\n");
71 displayArray(tab
, tab_length
);
72 printf("\nNow, sorting the array...\n");
73 sortArray(tab
, tab_length
);
74 printf("\nView array content sorted:\n");
75 displayArray(tab
, tab_length
);