bubble_sort örneği

#include <stdio.h>
#include <conio.h>
 
#define MAX_SIZE 50
 
void main(void);
void bubble_sort(double x[], int n);
 
void main(void)
{
   double x[MAX_SIZE];
   int num_items;
   int i;
 
   printf("\n BUBBLE SORT");
   printf("\n Listedeki eleman sayisi (Max=50) : ");
   scanf("%d",&num_items);
 
   for ( i = 0; i < num_items; ++i )
   {
      printf("\n%d. sayi : ",i+1);
      scanf("%lf",&x[i]);
   }
 
   bubble_sort(x,num_items);
 
   printf("\n\nSayilarin Siralanmis Hali : ");
 
   for ( i = 0; i < num_items; ++i )
    printf(" %.lf ",x[i]);
 
   getch();
}
 
 
void bubble_sort(double x[], int n)
{
   double temp;
   int pass;
   int i;
 
   for (pass = 0; pass < n - 1; ++pass)
   {
         for (i = 0; i < n - 1; ++i)
         {
             if (x[i] > x[i+1])
             {
                    temp = x[i];
                 x[i] = x[i+1];
                 x[i+1] = temp;
             }
         }
   }
}