Cleaned up src/sorting/.
[parallel_computing.git] / src / sorting / bubble.c
index 65683139ff433cf02e6c4ef438656b8b7d00c0b8..d747d63b1da7e4341a4c761893b224a2fd192279 100644 (file)
@@ -1,41 +1,11 @@
+/* Bubble sort algorithm */
 
-//
-//               Bubble sort algorithm
-//
-//                                        Michel Vallieres, 2009
-//
+/* Michel Vallieres, 2009 */
 
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include "main.h"
 
 
-void init( double * list, int list_size )
-{
-  int i;
-
-  for( i=0; i<list_size ; i++ )
-    {
-      list[i] = (double)rand()/(double)RAND_MAX;
-    }
-}
-
-
-void printlist(double * list, int n, int list_size )
-{
-   int i;
-   for(i=0;i<n;i++)
-      printf("%f\t",list[i]);
-   printf("\n");
-   for(i=n;i>0;i--)
-      printf("%f\t",list[list_size-i]);
-   printf("\n");
-}
-
-
-
-void sort( double * list, int list_size )
+void sort(int list_size, double *list)
 {
   double temp;
   int i, exchange;
@@ -56,45 +26,3 @@ void sort( double * list, int list_size )
        }
     }
 }
-
-
-double checklist(double list[], int list_size )
-{
-  int i;
-  double sum;
-
-  sum = 0.0;
-  for(i = 0; i < list_size; i++ )
-    sum = sum + list[i];
-  return sum;
-}
-
-
-int main ( int argc, char *argv[] )
-{
-  const int MAX_ELEMENTS = 1000000;
-  double list[MAX_ELEMENTS];
-  int list_size;
-
-                         /* size of lit */
-  list_size = 1000;
-
-                         /* initial a list of random numbers */
-  init( list, list_size );
-
-                         /* print initial list */ 
-  printf("The list before sorting is:\n");
-  printlist( list, 3, list_size );
-  printf( "Check: sum of %d elements = %f\n",
-          list_size, checklist( list, list_size ) );
-
-                         /* sort out the list */
-                         /* via bubble sort algorithm */
-  sort( list, list_size );
-
-                         /* print final list */ 
-  printf("The list after sorting is:\n");
-  printlist( list, 3, list_size );
-  printf( "Check: sum of %d elements = %f\n",
-          list_size, checklist( list, list_size ) );
-}