From 77df5b4e77934773a2873f2aad6df7159922106c Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 29 Oct 2010 11:36:39 -0400 Subject: [PATCH] Add sort check to src/sorting/main.c's DEBUG code. --- src/sorting/main.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/sorting/main.c b/src/sorting/main.c index 6246384..2fc6fb4 100644 --- a/src/sorting/main.c +++ b/src/sorting/main.c @@ -82,9 +82,12 @@ int read_data(const char *file_name, int *pList_size, double **pList) int main(int argc, char *argv[]) { - int list_size, i; + int list_size; double *list; char *file_name = "-"; +#ifdef DEBUG + int i; +#endif /* DEBUG */ // parse arguments if (argc > 1) @@ -111,6 +114,13 @@ int main(int argc, char *argv[]) printlist(stderr, list_size, list, NUM_SHOWN); fprintf(stderr, "Check: sum of %d elements = %g\n", list_size, checklist(list_size, list)); + for (i=0; i < list_size-1; i++) { + if (list[i] > list[i+1]) { + fprintf(stderr, "Error: sorted list[%d] = %g > %g = list[%d]\n", + i, list[i], list[i+1], i+1); + exit(EXIT_FAILURE); + } + } #endif /* DEBUG */ printlist(stdout, list_size, list, 0); -- 2.26.2