Bubble Sort in C

BUBBLE SORT

#include <stdio.h>
#define MAX 10

void swap(int *x,int *y)
{
   int temp;
   temp = *x;
   *x = *y;
   *y = temp;
}
void bsort(int list[])
{
   int i,j;
   for(i=0;i<(MAX-1);i++){
      for(j=0;j<(MAX-(i+1));j++){
             if(list[j] > list[j+1]){
                    swap(&list[j],&list[j+1]);
             }
      }
   }
}
void printlist(int list[])
{
   int i;
   printf("The elements of the list are: \n");
   for(i=0;i<MAX;i++)
      printf("%d\t",list[i]);
}

void main()
{
   int list[MAX];

   list[0] = 2; list[1] = 1; list[2] = 4; list[3] = 3; list[4] = 9;
   list[5] = 19; list[6] = 17; list[7] = 11; list[8] = 5; list[9] = 6;

   printf("The list before sorting is:\n");
   printlist(list);
   bsort(list);
   printf("The list after sorting is:\n");
   printlist(list);
}

Comments

Popular posts from this blog

Error : DependencyManagement.dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: com.adobe.aem:uber-jar:jar:apis -> version 6.3.0 vs 6.4.0

ERROR Exception while handling event Sitecore.Eventing.Remote.PublishEndRemoteEventException: System.AggregateExceptionMessage: One or more exceptions occurred while processing the subscribers to the 'publish:end:remote'

Error : Sorry, there was an error : unauthorized_client in Sitecore 9.1 login