C language bubble sort algorithm

  • 2020-04-02 03:00:43
  • OfStack

BubblSort. C


#include<stdio.h>
 
 
void BubbleSort(int a[],int len)
{
  int i;
  int j;
  int h;
  int temp;
  for(i=0;i<len-1;++i)
  {
    for(j=len-1;j>i;--j)
    {
      if(a[j]<a[j-1])
      {
         
        temp=a[j];
        a[j]=a[j-1];
        a[j-1]=temp;
         
      }
    }
      for(h=0;h<len;h++)
      {
        printf(" %d",a[h]);
      }
        printf("n");
  }
}
 
int main()
{
  int i=0;
  int a[]={36,25,48,12,25,65,43,57};
  int len=sizeof(a)/sizeof(a[0]);
  BubbleSort(a,len);
  {
    for(i=0;i<len;i++)
      printf(" %d",a[i]);
  }
  printf("n");
  return 0;
}

The above is all the content of this article, hope to help you learn C language.


Related articles: