Leadsort written in C

The sorting algorithm “leadsort” is a variant of “bubblesort” that allows you to sort the array in reverse. Computational complexity= O(n^2).

Source Code written in C language:


// © Codeido - www.codeido.com - Developed by Paolo Musolino

#include <stdio.h>

void swap(int *a, int *b)
{	
	int temp;
	temp=*a;
	*a=*b;
	*b=temp;
	
	
}
//---------------//---------------//---------------
int confronto(int x, int y)
{
	if(x<y) return -1;
	else if(x>y) return 1;
	else {
		return 0;
	}
	
}

void leadSort(int a[], int n)
{
	int i, j;
	
	for (i=n; i>1; i--) {
		for (j=1; j<i; j++) {
			if (confronto(a[j],a[j-1])<0) {
				swap(&a[j], &a[j-1]);
			}
		}
	}
	
}

int main ()
{
	int a[14]={5, 10, 11, 9, 7, 8, 4, 5, 7, 2, 45, 1, 4, 20};
	int i;
	leadSort(a, 14);
	printf("\n");
	for (i=0; i<14; i++) {
		printf("%d ", a[i]);
	}
	
	
	return 0;
}

4 thoughts on “Leadsort written in C

  1. Appreciate it for taking the time to discuss this, I feel strongly about it and love learning more on this subject. If possible, as you gain expertise, would you mind updating your blog site with more information? It is extremely handy for me.

Leave a Reply to zayiflama lida fx15 ve biber hapi zlfvbh Cancel reply

Your email address will not be published. Required fields are marked *