#include <stdlib.h>
#include <stdio.h>

#define CMP(a,b) ((a==b)?0:(a<b)?-1:1)
#define uint32 int
#define ARRAY_SIZE 100

int my_array[ARRAY_SIZE];

void ArraySort(int This[], uint32 ub)
{
  /* bubble sort */

  uint32 indx;
  uint32 indx2;
  int temp;
  int temp2;
  int flipped;

  if (ub <= 1)
    return;

  indx = 1;
  do
  {
    flipped = 0;
    for (indx2 = ub - 1; indx2 >= indx; --indx2)
    {
      temp = This[indx2];
      temp2 = This[indx2 - 1];
      if (CMP(temp2, temp) > 0)
      {
        This[indx2 - 1] = temp;
        This[indx2] = temp2;
        flipped = 1;
      }
    }
  } while ((++indx < ub) && flipped);
}

void fill_array()
{
  int indx;

  for (indx=0; indx < ARRAY_SIZE; ++indx)
  {
    my_array[indx] = rand();
  }
  /* my_array[ARRAY_SIZE - 1] = ARRAY_SIZE / 3; */
}

int main()
{
  int indx;

  fill_array();
  ArraySort(my_array, ARRAY_SIZE);
  for (indx=1; indx < ARRAY_SIZE; ++indx) {
    if (my_array[indx - 1] > my_array[indx]) {
      printf("bad sort\n");
      return(1);
    } else {
      printf("%d, ",my_array[indx-1]);
    }
  }
  return(0);
}
 
 
 
 

 back