add ouput from iteration to display it
authorJens Kasten <jens@kasten-edv.de>
Sat, 05 Mar 2011 19:15:35 +0100
changeset 3 7be71cab2ebf
parent 2 803affa7a5b4
child 4 5d1f5383d06d
add ouput from iteration to display it
bubblesort/bubblesort.c
--- a/bubblesort/bubblesort.c	Fri Mar 04 01:46:06 2011 +0100
+++ b/bubblesort/bubblesort.c	Sat Mar 05 19:15:35 2011 +0100
@@ -2,7 +2,7 @@
 #include <stdlib.h>
 #include <time.h>
 
-#define MAX_RAND 40
+#define MAX_RAND 10
 
 void create_random_pool(int *prandom_pool);
 void show_random_pool(int *prandom_pool);
@@ -42,7 +42,7 @@
 
 void sort_random_pool_to_less(int *prandom_pool)
 {
-    int i, j, temp;
+    int i, j, k, temp, counter = 1;
 
     for (i=0; i < MAX_RAND; i++) {
         for (j=0; j < MAX_RAND; j++) {
@@ -52,12 +52,19 @@
                 prandom_pool[i] = temp;
             }
         }      
+        printf("%2d. iteration: ", counter);
+        counter++;
+        for (k=0; k < MAX_RAND; k++) {
+            printf("%3d", prandom_pool[k]);
+        }
+        printf("\n");
+       
     }
 }
 
 void sort_random_pool_to_greater(int *prandom_pool)
 {
-    int i, j, temp;
+    int i, j, k, temp, counter = 1;
     
     for (i=MAX_RAND-1; i >= 0; i--) {
         for (j=MAX_RAND-1; j >= 0; j--) {
@@ -67,6 +74,12 @@
                 prandom_pool[i] = temp;
             }    
         }
+        printf("%2d. iteration: ", counter);
+        counter++;
+        for (k=0; k < MAX_RAND; k++) {
+            printf("%3d", prandom_pool[k]);
+        }
+        printf("\n");
     }
 }
     
@@ -83,7 +96,8 @@
 void show_random_pool(int *prandom_pool)
 {
     int i;
-     
+    
+    printf("Result: ");
     for (i=0; i < MAX_RAND; i++) {
         printf("%d ", prandom_pool[i]);
     }